[Python-ideas] with-statement syntactic quirk (original) (raw)
Barry Warsaw barry at python.org
Wed Oct 31 11:38:53 CET 2012
- Previous message: [Python-ideas] Support data: URLs in urllib
- Next message: [Python-ideas] with-statement syntactic quirk
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
with-statements have a syntactic quirk, which I think would be useful to fix. This is true in Python 2.7 through 3.3, but it's likely not fixable until 3.4, unless of course it's a bug .
Legal:
with open('/etc/passwd') as p1, open('/etc/passwd') as p2: pass
Not legal:
with (open('/etc/passwd') as p1, open('/etc/passwd') as p2): pass
Why is this useful? If you need to wrap this onto multiple lines, say to fit it within line length limits. IWBNI you could write it like this:
with (open('/etc/passwd') as p1,
open('/etc/passwd') as p2):
pass
This seems analogous to using parens to wrap long if-statements, but maybe there's some subtle corner of the grammar that makes this problematic (like 'with' treating the whole thing as a single context manager).
Of course, you can wrap with backslashes, but ick!
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/20121031/2de7ca35/attachment.pgp>
- Previous message: [Python-ideas] Support data: URLs in urllib
- Next message: [Python-ideas] with-statement syntactic quirk
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]