[Python-ideas] Parenthesized Compound With Statement
Barry Warsaw
barry at python.org
Wed Jul 3 17:01:47 CEST 2013
On Jul 02, 2013, at 06:37 PM, Matthew Lefavor wrote:
>As you all know, Python supports a compound "with" statement to avoid the
>necessity of nesting these statements.
>
>Unfortunately, I find that using this feature often leads to exceeding the
>79-character recommendation set forward by PEP 8.
Yeah, I noticed and brought this up a while ago. I thought I filed a bug but
can't find it. It would have been closed Won't Fix anyway.
As others have pointed out, you can usually rewrite such long with-statements
to conform to the PEP 8 line lengths by e.g. saving the paths in a shorter
named local variable), using Python 3.3's ExitStack, which is awesome btw, or
just using backslashes. Remember PEP 8 isn't a weapon to be wielded by a
stern Auntie Tim Peters.
As for relaxing PEP 8, well, I'm not sure what more you'd want it to say. It
currently reads:
The preferred way of wrapping long lines is by using Python's implied
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.
which seems about right to me. It is preferred to use implied continuation
over backslashes, but doesn't say "don't use backslashes". They're not evil,
just not preferred, so use them where appropriate and with good judgment.
Cheers,
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130703/34f989d3/attachment-0001.pgp>
More information about the Python-ideas
mailing list