proposed PEP: iterator splicing

Steven Bethard steven.bethard at gmail.com
Sun Apr 15 09:14:19 EDT 2007


Paul Rubin wrote:
> The boilerplate
>     
>     def some_gen():
>        ...
>        for x in some_other_gen():
>            yield x
>        ...
> 
> is so common (including the case where some_other_gen is the same as
> some_gen, i.e. it's a recursive call) that I find myself wanting
> a more direct way to express it:
> 
>     def some_gen():
>        ...
>        yield *some_other_gen()
> 
> comes to mind.  Less clutter, and avoids yet another temp variable
> polluting the namespace.
> 
> Thoughts?

This has been brought up before and there was mixed support:

http://www.python.org/dev/summary/2006-01-16_2006-01-31/#yielding-from-a-sub-generator

My guess is that the only way it has any chance is if someone takes the 
time to implement it and posts a full-fledged PEP to python-dev.

STeVe



More information about the Python-list mailing list