On Thu, 18 Oct 2012 02:06:19 -0400, Zero Piraeus wrote: > What are people's preferred strategies for dealing with lines that go > over 79 characters? A few I can think of off the bat: > > 1. Say "screw it" and go past 79, PEP8 be damned.
I've been burnt enough by word-wrapping in editors that don't handle word- wrapping that well that it makes me really uncomfortable to go over 78-79 characters, even by only 1 extra. So I don't like doing this. Just about the only time I go over is if I have a comment that includes a URL with more than 78 characters. I hate breaking URLs more than I hate breaking the 79 character limit. > 2. Say "screw it" and break the line using a backslash. Low on my preference list, but occasionally. > 3. Say "well, at least it's not a backslash" and break the line using > parentheses. I mostly do this. Since most lines include a bracket of some sort, I rarely need to add outer parentheses just for the purpose of line continuation. some_variable = spam('x') + ham( some_longer_variables, here_and_here, and_here_also) I know PEP 8 says I should drop the final round bracket to the next line, but I don't normally like that. > 4. Spend 45 minutes trying to think up shorter [but still sensible] > variable names to make it fit. Ha! Since most of my variable names are already relatively short, that's not often much help. > 5. Perform an otherwise pointless assignment to a temp variable on the > previous line to make it fit. Hardly ever. You missed one: 5a. Perform an assignment to a temp variable that you really should have done anyway, but reducing the number of characters in the line was the impetus that finally made you act. > 6. Realise that if it's that long, it probably shouldn't have been a > list comprehension in the first place. What if it wasn't a list comp in the first place? :) Refactoring code makes most long lines go away on their own. -- Steven -- http://mail.python.org/mailman/listinfo/python-list