Get returned by __enter__ in __exit__
<p>For example, i have this code:</p>

<pre><code>with MyClass() as x:
    print 'I have only {0}'.format(x)
    with MyClass() as y:
        print 'I have {0} and {1}'.format(x, y)
    print 'Again only {0}'.format(x)
</code></pre>

<p><code>x</code> and <code>y</code> both should be de-initialized after exit of corresponding <code>with</code> blocks. Also <code>x</code> and <code>y</code> aren't instances of <code>MyClass</code>.</p>

<p><code>__exit__</code> has only three arguments and each argument is None (if no exception supplied).</p>

<p>How can i determine at <code>__exit__</code> which block is just exited and what value was returned by <code>__enter__</code>?</p>

<p>(N.B. code should be thread-safe).</p>

<hr>

<p>Example:</p>

<pre><code>class MyClass(object):
    def __enter__(self):
        if moon_phase &gt; 0:
            return 123
        else:
            return 456
    def __exit__(self):
        number = what_was_returned_by_enter()
        print 'End of block with', number


 with MyClass() as x:
    print x  # 123
    with MyClass() as y:
        print x, 'and', y  # 123 and 456
    # printed "End of block with 456"
    print x  # 123
 # printed "End of block with 123"
</code></pre>
