[issue18677] Enhanced context managers with ContextManagerExit and None
Kristján Valur Jónsson
report at bugs.python.org
Thu Aug 8 12:43:07 CEST 2013
Kristján Valur Jónsson added the comment:
Using my latest patch, the ExitStack inline example can be rewritten:
with ExitStack() as stack:
files = [stack.enter_context(open(fname)) for fname in filenames]
# All opened files will automatically be closed at the end of
# the with statement, even if attempts to open files later
# in the list raise an exception
becomes:
with nested(opened(fname) for fname in filenames) as files:
do_stuff_with_files(files)
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18677>
_______________________________________
More information about the Python-bugs-list
mailing list