Tagged Questions
28
votes
8answers
3k views
How can I learn to effectively write Pythonic code?
Doing a google search for "pythonic" reveals a wide range of interpretations. The wikipedia page says:
A common neologism in the Python community is pythonic, which can have a wide range of ...
1
vote
2answers
191 views
Python code style - blank lines in long list
I'm curious, is there a standard approach to dealing with long lists in the Python community, and in particular, is there any antipathy toward doing blank lines followed by comments to break up a ...
5
votes
1answer
314 views
Is using '{}' within format strings considered Pythonic?
I just learned you can write
'{}{}'.format(string_a, string_b)
instead of
'{0}{1}'.format(string_a, string_b)
in Python, i.e. you can omit the numerals for the string format parameters when you ...
6
votes
3answers
2k views
Differences between “Java OOP” and “Pythonic OOP”? [closed]
I started with ActionScript 2.0 and then went on with Java. I have learned, or at least used, a bunch of languages since then, including Python (probably my favorite).
I'm afraid that my style of ...
12
votes
2answers
2k views
What's wrong with relative imports in Python?
I recently upgraded versions of pylint, a popular Python style-checker.
It has gone ballistic throughout my code, pointing out places where I import modules in the same package, without specifying ...
1
vote
3answers
201 views
Hacking Python “Requests” library.. How to start as an intermediate pythonista?
My question is conceptual, yet extremely vital for me.
I'm an intermediate Python developer. I know fair enough about it, and actually use it on a daily basis. Now, I would like to transform my ...
8
votes
2answers
270 views
In python, is it considered better to define a module with functions or a module with a class that contains functions? [closed]
In my code either of the above two options would work equally well but I am interested in finding out the pros and cons of both approaches.
5
votes
2answers
174 views
Questioning pythonic type checking
I've seen countless times the following approach suggested for "taking in a collection of objects and doing X if X is a Y and ignoring the object otherwise"
def quackAllDucks(ducks):
for duck in ...
23
votes
3answers
1k views
Python Forgiveness vs. Permission and Duck Typing
In Python, I often hear that it is better to "beg forgiveness" (exception catching) instead of "ask permission" (type/condition checking). In regards to enforcing duck typing in Python, is this
try:
...
4
votes
1answer
319 views
Pythonic use of the isinstance function?
Whenever I find myself wanting to use the isinstance() function I usually know that I'm doing something wrong and end up changing my ways. However, in this case I think I have a valid use for it. I ...
5
votes
2answers
193 views
Abstracting away the type of a property
In Python luckily most of the times you don't have to write getters and setters to get access to class properties. That said sometimes you'll have to remember that a certain property is a list or ...
2
votes
4answers
339 views
Give a more formal definition for the term “pythonic” than PEP8?
For me as python programmer having a formal definition for the term "pythonic" would be much more important and less subjective compared to asking more rhetoric (non-formal) questions. This may lead ...
4
votes
1answer
200 views
What is the typical Pythonic view on re-using python modules outside of their initial intent?
Short Question
Does it fly in the face of the Pythonic view to reuse / repurpose python modules for projects out side of their intent?
Background
Over the past several months I have been working on ...
5
votes
2answers
2k views
Why doesn't Python allow multi-line lambdas?
Can someone explain the concrete reasons why BDFL choose to make Python lambdas single line?
This is good:
lambda x: x**x
This results in an error:
lambda x:
x**x
I understand that making ...