Nick already proposed "with (yield from ...): ..."<div><br></div><div>Maybe in 3.4 we can tweak the syntax so the paresns are not needed.</div><div><br></div><div>I am quite glad that we had the foresight (when we designed 'with') to make this possible.<span></span><br>
<br>On Saturday, December 22, 2012, Andrew Svetlov  wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Crazy idea.<br>
Guido van Rossum mentioned after working on PEP 3156 that context<br>
managers cannot use<br>
yield from statement inside __enter__ and __exit__ magic methods.<br>
Explicit call for entering and leaving context (for locking for<br>
example) is not convenient.<br>
<br>
What do you think about<br>
<br>
with from f():<br>
   do_our_work()<br>
<br>
<br>
``with from ...` construction calls __enter_from__ generator  and<br>
iterates via ``yield from`` for that.<br>
Returned value is our context manager.<br>
<br>
The same for __exit_from__ — do``yield from`` for that and stop on<br>
StopIteration or exception.<br>
<br>
--<br>
Thanks,<br>
Andrew Svetlov<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="javascript:;" onclick="_e(event, 'cvml', 'Python-ideas@python.org')">Python-ideas@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/mailman/listinfo/python-ideas</a><br>
</blockquote></div><br><br>-- <br>--Guido van Rossum (<a href="http://python.org/~guido">python.org/~guido</a>)<br>