On Thu, 28 Jul 2022 at 08:57, Marco De Paoli <depao...@gmail.com> wrote:
> = > ---><--- begin test_gen.py ---><--- > def gen(): > while True: > try: > yield "A" > yield "B" > yield "C" > except Exception as ex: > print("catched exception", ex) > > > g = gen() > you_can_specify_any_number_of_steps = 3 > for idx in range(you_can_specify_any_number_of_steps): > print("result:", g.send(None)) > print("throw...") > g.throw(Exception("BOOM")) > print("result:", g.send(None), "*** I was expecting A and I get B, why?!? > ***") > print("result:", g.send(None)) > > Se invece di g.throw(Exception("BOOM")) scrivi print( g.throw(Exception("BOOM"))) Ritroverai il tuo "A" :-) Ciao. Marco. > >
_______________________________________________ Python mailing list Python@lists.python.it https://lists.python.it/mailman/listinfo/python