proposed PEP: iterator splicing

Georg Brandl g.brandl at gmx.net
Sun Apr 15 13:00:37 EDT 2007


Steven Bethard schrieb:
> 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.

BTW, I've implemented a different feature, namely extended unpacking, such as

a, *b, c = range(10)

where I already had to add the concept of a ``starred'' expression.
If someone wants to do it, we can probably share some code.


Georg


-- 
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.




More information about the Python-list mailing list