On 2013-09-02, Roy Smith <[email protected]> wrote:
> In article <[email protected]>,
> "albert visser" <[email protected]> wrote:
>
>> I like being able to do e.g.
>>
>> with open('some_file') as _in, open('another_file', 'w') as _out:
>
> It would be nice if you could write that as:
>
> with open('some_file'), open('another_file, 'w') as _in, _out:
3.2 and above provide contextlib.ExitStack, which I just now
learned about.
with contextlib.ExitStack() as stack:
_in = stack.enter_context(open('some_file'))
_out = stack.enter_context(open('another_file', 'w'))
It ain't beautiful, but it unfolds the nesting and gets rid of
the with statement's line-wrap problems.
--
Neil Cerutti
--
https://mail.python.org/mailman/listinfo/python-list