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.
|
limiting the length to 72 characters is recommended.
|
||||||
|
|
||||||
The preferred way of wrapping long lines is by using Python's implied line
|
The preferred way of wrapping long lines is by using Python's implied line
|
||||||
continuation inside parentheses, brackets and braces. If necessary, you
|
continuation inside parentheses, brackets and braces. Long lines can be
|
||||||
can add an extra pair of parentheses around an expression, but sometimes
|
broken over multiple lines by wrapping expressions in parentheses. These
|
||||||
using a backslash looks better. Make sure to indent the continued line
|
should be used in preference to using a backslash for line continuation.
|
||||||
appropriately. The preferred place to break around a binary operator is
|
Make sure to indent the continued line appropriately. The preferred place
|
||||||
*after* the operator, not before it. Some examples:
|
to break around a binary operator is *after* the operator, not before it.
|
||||||
|
Some examples:
|
||||||
|
|
||||||
class Rectangle(Blob):
|
class Rectangle(Blob):
|
||||||
|
|
||||||
def __init__(self, width, height,
|
def __init__(self, width, height,
|
||||||
color='black', emphasis=None, highlight=0):
|
color='black', emphasis=None, highlight=0):
|
||||||
if width == 0 and height == 0 and \
|
if (width == 0 and height == 0 and
|
||||||
color == 'red' and emphasis == 'strong' or \
|
color == 'red' and emphasis == 'strong' or
|
||||||
highlight > 100:
|
highlight > 100):
|
||||||
raise ValueError("sorry, you lose")
|
raise ValueError("sorry, you lose")
|
||||||
if width == 0 and height == 0 and (color == 'red' or
|
if width == 0 and height == 0 and (color == 'red' or
|
||||||
emphasis is None):
|
emphasis is None):
|
||||||
|
@ -768,18 +769,6 @@ Programming Recommendations
|
||||||
|
|
||||||
if isinstance(obj, basestring):
|
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
|
- For sequences, (strings, lists, tuples), use the fact that empty
|
||||||
sequences are false.
|
sequences are false.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue