[Python-Dev] yield * (Re: Missing operator.call) (original) (raw)

glyph at divmod.com glyph at divmod.com
Sun Feb 8 02:50:07 CET 2009


On 01:00 am, greg.ewing at canterbury.ac.nz wrote:

Guido van Rossum wrote:

We already have yield expressions and they mean something else... They don't have a "*" in them, though, and I don't think the existing meaning of yield as an expression would carry over into the "yield *" variant, so there shouldn't be any conflict. But if you think there will be a conflict, or that the similarity would be too confusing, maybe the new construct should be called something else. I'm open to suggestions.

I'm already regretting poking my head into this particular bike shed, but...

has anyone considered the syntax 'yield from iterable'? i.e.

def foo():
    yield 1
    yield 2

def bar():
    yield from foo()
    yield from foo()

list(bar()) -> [1, 2, 1, 2]

I suggest this because (1) it's already what I say when I see the 'for' construct, i.e. "foo then yields all results from bar", and (2) no new keywords are required.



More information about the Python-Dev mailing list