2012/6/14 piergiorgio pancino <piert...@yahoo.it>

> ho provato a creare questa classe per provare with, ...
>
> che mi da come risultato:
> Init eseguito
> Enter eseguito
> Sto eseguendo
> Sto eseguendo
> Sto eseguendo
> Sto eseguendo
> Sto eseguendo
> exit eseguito
>
>
oppure, sfruttando yield, potresti fare una cosa del genere...

from contextlib import contextmanager

@contextmanager
def prova_with():
    print("init eseguito")
    yield
    print ("exit eseguito")

def funzione():
    return "sto
eseguendo"

with prova_with():
    for idx in range(5):
        print(funzione())


non è esattamente equivalente al tuo, però mostra un uso di yield associato
a with

Marco
_______________________________________________
Python mailing list
Python@lists.python.it
http://lists.python.it/mailman/listinfo/python

Rispondere a