[Python-ideas] Allow parentheses to be used with "with" block
Terry Reedy
tjreedy at udel.edu
Mon Feb 16 01:27:47 CET 2015
On 2/15/2015 4:52 PM, Neil Girdhar wrote:
> It's great that multiple context managers can be sent to "with":
>
> with a as b, c as d, e as f:
> suite
>
> If the context mangers have a lot of text it's very hard to comply with
> PEP8 without resorting to "\" continuations, which are proscribed by the
> Google style guide.
Untrue. " 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())"
> Other statements like import and if support enclosing their arguments in
> parentheses to force aligned continuations. Can we have the same for
> "with"?
No. Considered and rejected because it would not be trivial.
--
Terry Jan Reedy
More information about the Python-ideas
mailing list