Nick Coghlan <ncogh...@gmail.com> added the comment:

The comparison to Go's defer statement is interesting, though: 
ContextStack.register basically *is* the same as defer. While a nested with 
statement is a better option in Python, if we ignore that for the moment, you 
*could* write that simply copying example:

    with ContextStack() as stack:
        src = open(source)
        stack.register(src.close)
        dest = open(destination, 'w')
        stack.register(dest.close)
        copy(src, dest)

However, since ContextStack is just an ordinary context manager class, you have 
a lot of flexibility in what you do with it (particularly once I add the 
preserve() API to let you deliberately *skip* the cleanup steps by transferring 
them to a new ContextStack object)

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue13585>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to