Request for elucidation: enhanced generators

Steve Holden steve at holdenweb.com
Wed Sep 20 07:16:32 EDT 2006


Ben Sizer wrote:
> A simple question - can anybody give a short example of how these work
> and what they are good for? I've read PEP 342 and the associated bit in
> the What's New section and it's still all Greek to me. The latter seems
> to focus on how to do it, rather than why you'd do it, so it doesn't
> aid the understanding too much.
> 
Unti 2.5 the yield keyword could only be used to produce a value from a 
generator - it introduced a statement.

Now the yield keyword can be used as an expression inside a generator, 
allowing you to send values into the generator by calling its .send() 
method.

If you have no use case for this you are, as always, perfectly free to 
ignore it, as the majority of Python users may well choose to do. Your 
existing generators should continue to work.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb       http://holdenweb.blogspot.com
Recent Ramblings     http://del.icio.us/steve.holden




More information about the Python-list mailing list