Modify the advice on line continuations to not recommend backslashes.
As discussed with Guido. Also remove references to Python 2.0, 2.1 and 2.2
This commit is contained in:
parent
8def3e9cac
commit
3b0897884e
29
pep-0008.txt
29
pep-0008.txt
|
@ -84,19 +84,20 @@ Code lay-out
|
|||
limiting the length to 72 characters is recommended.
|
||||
|
||||
The preferred way of wrapping long lines is by using Python's implied line
|
||||
continuation inside parentheses, brackets and braces. If necessary, you
|
||||
can add an extra pair of parentheses around an expression, but sometimes
|
||||
using a backslash looks better. Make sure to indent the continued line
|
||||
appropriately. The preferred place to break around a binary operator is
|
||||
*after* the operator, not before it. Some examples:
|
||||
continuation inside parentheses, brackets and braces. Long lines can be
|
||||
broken over multiple lines by wrapping expressions in parentheses. These
|
||||
should be used in preference to using a backslash for line continuation.
|
||||
Make sure to indent the continued line appropriately. The preferred place
|
||||
to break around a binary operator is *after* the operator, not before it.
|
||||
Some examples:
|
||||
|
||||
class Rectangle(Blob):
|
||||
|
||||
def __init__(self, width, height,
|
||||
color='black', emphasis=None, highlight=0):
|
||||
if width == 0 and height == 0 and \
|
||||
color == 'red' and emphasis == 'strong' or \
|
||||
highlight > 100:
|
||||
if (width == 0 and height == 0 and
|
||||
color == 'red' and emphasis == 'strong' or
|
||||
highlight > 100):
|
||||
raise ValueError("sorry, you lose")
|
||||
if width == 0 and height == 0 and (color == 'red' or
|
||||
emphasis is None):
|
||||
|
@ -768,18 +769,6 @@ Programming Recommendations
|
|||
|
||||
if isinstance(obj, basestring):
|
||||
|
||||
In Python 2.2, the types module has the StringTypes type defined for
|
||||
that purpose, e.g.:
|
||||
|
||||
from types import StringTypes
|
||||
if isinstance(obj, StringTypes):
|
||||
|
||||
In Python 2.0 and 2.1, you should do:
|
||||
|
||||
from types import StringType, UnicodeType
|
||||
if isinstance(obj, StringType) or \
|
||||
isinstance(obj, UnicodeType) :
|
||||
|
||||
- For sequences, (strings, lists, tuples), use the fact that empty
|
||||
sequences are false.
|
||||
|
||||
|
|
Loading…
Reference in New Issue