<div dir="ltr">On Thu, Nov 1, 2012 at 1:40 PM, Nick Coghlan <span dir="ltr"><<a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a>></span> wrote:<div class="gmail_extra"><div class="gmail_quote">

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">I've been remiss in not mentioning the new alternative in 3.3 for<br>


handling nesting of complex context management stacks:<br>
<br>
    with contextlib.ExitStack() as cm:<br>
        p1 = cm.enter_context(open('/etc/passwd'))<br>
        p2 = cm.enter_context(open('/etc/passwd'))<br>
<br>
(Note: ExitStack is really intended for cases where the number of<br>
context managers involved varies dynamically, such as when you want to<br>
make a CM optional, but you *can* use it for static cases if it seems<br>
appropriate)<br>
<div class="im"><br></div></blockquote><div><br></div><div>Go's "defer" is quite a neat solution for these hassles if anyone's in the mood for a time machine discussion.</div><div><br></div><div><a href="http://golang.org/doc/effective_go.html#defer">http://golang.org/doc/effective_go.html#defer</a><br>

</div><div><br></div><div>Yuval Greenfield</div></div></div></div>