My current editor (Kate) has been configured to introduce line breaks at word boundaries whenever a line reaches or exceeds 80 characters. From here it immediately becomes apparent that I have stepped over the boundaries. In addition, there is a red line indicating the position of 80 characters, giving me a preliminary warning about when the line will flow. This allows me to plan logical lines that will correspond to many physical lines.
As for how to properly adjust them, there are several mechanisms. You can end the line with \, but this is a mistake.
# works print 4 + \ 2
Difference? The difference is invisible - after the backslash in the second case, there was a space character. Unfortunately,
What should be done instead? Well, surround it in parentheses.
print (4 + 2)
Not necessary. It really works all over the place; you'll never need it. Even for the boundaries of access to attributes!
print (foo .bar())
For strings, you can add them explicitly or implicitly using a C-style join.
# all of these do exactly the same thing print ("123" "456") print ("123" + "456") print "123456"
Finally, anything that will be in any form brackets ((), []. {}), And not just in brackets, in particular, can have a line break anywhere. So, for example, you can use a list literal over multiple lines just fine if the items are separated by a comma.
All of this and more can be found in the official documentation for Python. In addition, the quick note PEP-8 defines 79 characters as a limit, not 80-- if you have 80 characters, you have already completed it.
Devin Jeanpierre Jan 15 '10 at 10:14 2010-01-15 10:14
source share