[Python-ideas] A different kind of context manager
Nick Coghlan
ncoghlan at gmail.com
Mon Oct 21 16:51:45 CEST 2013
No, it wouldn't. Read PEP 340 (the one Guido wrote *before* descoping it in
PEP 343).
The problem with offering true blocks is that they immediately create
multiple ways to do a lot of different things, and this callback based
variant also plays merry hell with the scoping rules.
That said, something I *have* been thinking might work better than the
status quo is permitting a variant of tuple unpacking that enters each
context manager as it is produced and provides a tuple of the results. So
this would work properly:
with *(open(name) for name in names) as files:
...
And you could factor out with statement skipping as a function returning a
2-tuple (although unpacking the value would be a little annoying in that
case).
Cheers,
Nick.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20131022/7450fdb2/attachment.html>
More information about the Python-ideas
mailing list