semicolon at end of python's statements
Neil Cerutti
neilc at norwich.edu
Tue Sep 3 13:15:36 EDT 2013
On 2013-09-02, Roy Smith <roy at panix.com> wrote:
> In article <mailman.508.1378143885.19984.python-list at python.org>,
> "albert visser" <albert.visser at gmail.com> 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
More information about the Python-list
mailing list