Steve Holden wrote: > 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.
But do you have an example of such a use case? That's what I'm missing here. Without ever having used proper coroutines elsewhere, I have no real way to appreciate their benefits without a good example. I don't think it's feasible to just ignore any new feature, as sooner or later you're going to encounter someone else's code that relies upon it. Hence why I'd rather not see all sorts of 'optional' extras added later (like type declarations and so on). -- Ben Sizer -- http://mail.python.org/mailman/listinfo/python-list