[issue13585] Add contextlib.ExitStack
Nick Coghlan
report at bugs.python.org
Tue May 1 14:22:42 CEST 2012
Nick Coghlan <ncoghlan at gmail.com> added the comment:
Latest draft of API is here: http://contextlib2_dev.readthedocs.org/en/latest/index.html#contextlib2.ExitStack
An updated version of the "I forgot I could use multiple context managers in a with statement" example:
with ExitStack() as stack:
src = open(source)
stack.callback(src.close)
dest = open(destination, 'w')
stack.callback(dest.close)
copy(src, dest)
The example of opening a collection of files remains unchanged (aside from s/ContextStack/ExitStack/).
Also see: http://contextlib2_dev.readthedocs.org/en/latest/index.html#replacing-any-use-of-try-finally-and-flag-variables
----------
assignee: rhettinger -> ncoghlan
resolution: later ->
title: Add contextlib.CallbackStack -> Add contextlib.ExitStack
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13585>
_______________________________________
More information about the Python-bugs-list
mailing list