[Python-Dev] return from a generator [was:PEP 380 (yield from a subgenerator) comments]
Jim Jewett
jimjjewett at gmail.com
Fri Mar 27 06:25:35 CET 2009
On Thu, Mar 26, 2009 at 4:19 PM, P.J. Eby wrote:
>> What I don't like is the confusion of adding "return values" to generators,
>> at least using the 'return' statement.
At Fri Mar 27 04:39:48 CET 2009, Guido van Rossum replied:
> I'm +1 on "yield from" and +0 on return values in generators.
> def g():
> yield 42
> return 43
> for x in g():
> print x # probably expected to print 42 and then 43
I still don't see why it needs to be a return statement. Why not make
the intent of g explicit, by writing either
def g():
yield 42
yield 43
or
def g():
yield 42
raise StopIteration(43)
-jJ
More information about the Python-Dev
mailing list