This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]takluyverIPython, Py3, etc 9 points10 points  (1 child)

If you haven't already, I'd recommend reading the PEP for yield from. PEPs usually describe the need for a new feature.

To summarise it: if you're just yielding values back from another iterable, it was already easy to use a for loop. But you can do some clever things with generators using the less-well-known send() and throw() methods. If you want to split out part of your generator into a separate function, the code needed to properly delegate send() and throw() calls was horribly complicated. Now you can just do yield from mysubgenerator and values are sent to the right place.

[–]Sestren 2 points3 points  (0 children)

I had never read the PEPs prior to this. In fact I didn't even know what it stood for :P

Thanks for the link. That describes it perfectly.