proposed PEP: iterator splicing

Carsten Haese carsten at uniqsys.com
Sun Apr 15 02:49:18 EDT 2007


On 14 Apr 2007 22:17:08 -0700, 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?

Explicit is better than implicit. The explicit boilerplate code is more
readable and tells the reader exactly what's going on. Since the namespace is
the local namespace of your generator function, the namespace pollution is
minimal.

-Carsten




More information about the Python-list mailing list