Please comment on PEP XXX: Enhanced Generators
Paul Rubin
phr-n2002a at nightsong.com
Fri Feb 1 06:17:40 EST 2002
Oren Tirosh <oren-py-l at hishome.net> writes:
> > 2. Generator comprehensions: [yield int(x) for x in floatgen()]
>
> The only problem I see with this syntax is that the square brackets are
> misleading - the resulting object is not a list. How about using parens
> instead? They are not strictly required, but just like for tuples, they
> help disambiguate the syntax.
Actually there's sort of a worse problem with either version, which is
how it interacts with the proposal that yield can return a value.
If I can say "x = yield 3", then can't I say
x = [yield 3, yield 4, yield 5]
which should suspend execution 3 times before actually assigning to x?
And if I can do that, can't I say the same thing as a list (not
generator!) comprehension
x = [yield i for i in range(3,5)]
I realize that in the original proposal, yield can't necessarily take
an arbitrary argument when it returns a value sent by .submit(), but
the option of doing that (to have fully general coroutines) should be
left open.
More information about the Python-list
mailing list