<br><br><div class="gmail_quote">2012/6/14 piergiorgio pancino <span dir="ltr"><<a href="mailto:piertoni@yahoo.it" target="_blank">piertoni@yahoo.it</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div style="font-size:10pt;font-family:lucida console,sans-serif"><div><div><span style="font-size:14px">ho provato a creare questa classe per provare with, ...</span></div><br><div><span style="font-size:14px">che mi da
 come risultato:</span></div><div><span style="font-size:14px"><div>Init eseguito</div><div>Enter eseguito</div><div>Sto eseguendo</div><div>Sto eseguendo</div><div>Sto eseguendo</div><div>Sto eseguendo</div><div>Sto eseguendo</div>
<div>exit eseguito</div><div><br></div></span></div></div></div></div></blockquote><br>oppure, sfruttando yield, potresti fare una cosa del genere...<br><br>from contextlib import contextmanager<br><br>@contextmanager<br>
def prova_with():<br>    print("init eseguito")<br>    yield<br>    print ("exit eseguito")<br><br>def funzione():<br>    return "sto eseguendo"                                                      <br>
<br>with prova_with():<br>    for idx in range(5):<br>        print(funzione())<br><br><br>non č esattamente equivalente al tuo, perņ mostra un uso di yield associato a with<br><br>Marco<br></div>