11
votes
2answers
440 views

Creating nested functions for purely aesthetic reasons?

I've always wondered what other programmers think about the idea of creating pure aesthetic functions. Say I have a function that processes a chunk of data: Function ProcessBigData. Say I need ...
0
votes
0answers
47 views

Check some value between each function call

Can you recommend a nice way of checking a particular value between calls to a set of functions? E.g. something like this in Python (might not be terribly 'Pythonic'): self.error_code = 0 # this ...
5
votes
4answers
336 views

Communicate to a junior developer about bad style

I have a friend who's managed to pick up comma first (best case might be made here: http://ajaxian.com/archives/is-there-something-to-the-crazy-comma-first-style) but it's 100% against our org's style ...
5
votes
4answers
420 views

How can I stop myself overwriting member variables with 'new' ones?

The bulk of my programming experience has been with C++ and (shudder) FORTRAN (I'm a scientist not a programmer as such, but I do my best). I've recently started using python extensively and find it ...
0
votes
1answer
194 views

How to format this line according to PEP 8? [closed]

I'm trying to adhere to PEP 8, with a 78 character limit on the length of my lines. I have the following statement: startTime = time.strptime(request.GET.get('st', (dt.datetime.now() - ...
3
votes
2answers
238 views

How can I keep current with Python coding style?

I've been using Python since version 2.2. I do pick up new language constructs like for example with statement or dictionary/set comprehensions. However, I've realized that even though I'm being ...
4
votes
3answers
433 views

Space between negative sign and variable name

I tried doing a Google search, as well as searching this Stack Exchange site but could not find a question relating directly to this. The PEP 8 -- Style Guide for Python Code has lots of good style ...
7
votes
1answer
368 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 ...
2
votes
1answer
695 views

call sub function based on variable value

I have a function containing other functions. These function are called based on value of variable action. These sub functions are logically grouped - i.e., they all deal with file manipulation. ...
5
votes
1answer
1k 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 ...
20
votes
2answers
9k 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 ...
8
votes
6answers
7k views

Single quotes vs double quotes [closed]

I just started a job where I'm writing Python after coming from a Java background, and I'm noticing that other developers tend to quote strings using single quotes ('') instead of double quotes (""). ...
5
votes
3answers
292 views

Should I return iterators or more sophisticated objects?

Say I have a function that creates a list of objects. If I want to return an iterator, I'll have to return iter(a_list). Should I do this, or just return the list as it is? My motivation for returning ...
7
votes
5answers
1k views

Which style to use for unused return parameters in a Python function call

Is there any recommended/generally accepted coding style for handling situations where a function returns a tuple of values but only one of those values is used afterwards (note that this is mostly ...
34
votes
8answers
5k 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 ...