[Python-ideas] 80 character line width vs. something wider

Raymond Hettinger python at rcn.com
Thu May 21 18:59:13 CEST 2009


[Lie Ryan] 
> This is how I will write program if we have 160 character limit:
> 
> def foo(f, a, b, c):
>     return [[((f(x, y) * i, i) if i % 2 else 0) for i, x in 
> enumerate(a) if f(y, x) == a + x] for y in [c(z) for z in range(a, a * b 
> + c, c)]]
> 
> except there will be no line breaks...
> 
> I love list comprehension so much that I often _unconsciously_ write a 
> very complex list comprehensions. 80-character convention acts as a 
> reminder to consider refactoring.

that makes sense to because your example starts close to the left margin.
What I'm more concerned about is lines that start many tabs deep.
Those become awkward, causing you to wrap them differently than
if they were not tabbed.  So, I think the 80 char limit should be relaxed
only when there is a bunch of whitespace to the left.  Your cues for
refactoring  and coding style should not depend on the initial level 
of indentation.


Raymond



More information about the Python-ideas mailing list