http://qs321.pair.com?node_id=1030269


in reply to Re^3: RFC: Simulating Ruby's "yield" and "blocks" in Perl
in thread RFC: Simulating Ruby's "yield" and "blocks" in Perl

> FWIW, the equivalent in idiomatic Python3 is:

Thanks, interesting idea to turn it inside out! =)

But why Python3, AFAIK generators were already introduced in 2.

> while back a monstrosity was released...

Thanks, even more fun! =)

Especially the last line (after "bugs and limitations")

Oh, and almost forgot: We are sorry, Guido. So sorry.

Grin! xD

Cheers Rolf

( addicted to the Perl Programming Language)

update

) while its a bit cumbersome that you need to iterate over the yields... ... why not using a decorator to abstract the loop away?

update

this worked for me in Py 2.5.2

>>> def test(): ... print("You are in the method") ... yield 1 ... print("You are again back to the method") ... yield 2 ... >>> for a in test(): ... print("You are in the block "+str(a)) ... You are in the method You are in the block 1 You are again back to the method You are in the block 2