[Python-checkins] peps: Relax PEP 8's perceived (but incorrect) prohibition against backslashed.
barry.warsaw
python-checkins at python.org
Wed Jul 3 19:26:44 CEST 2013
http://hg.python.org/peps/rev/98f42236d1af
changeset: 4973:98f42236d1af
user: Barry Warsaw <barry at python.org>
date: Wed Jul 03 13:26:36 2013 -0400
summary:
Relax PEP 8's perceived (but incorrect) prohibition against backslashed.
files:
pep-0008.txt | 18 +++++++++++++++---
1 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/pep-0008.txt b/pep-0008.txt
--- a/pep-0008.txt
+++ b/pep-0008.txt
@@ -158,9 +158,21 @@
line 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::
+for line continuation.
+
+Backslashes may still be appropriate at times. For example, long,
+multiple ``with``-statements cannot use implicit continuation, so
+backslashes are acceptable::
+
+ with open('/path/to/some/file/you/want/to/read') as file_1, \
+ open('/path/to/some/file/being/written', 'w') as file_2:
+ file_2.write(file_1.read())
+
+Another such case is with ``assert`` statements.
+
+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):
--
Repository URL: http://hg.python.org/peps
More information about the Python-checkins
mailing list