Ron Adam wrote:
P.J. Eby wrote:
Sure. But right now, the return value of a generator function *is the
generator*. And you're free to ignore that, sure.
But this is a "second" return value that only goes to a special place
with special syntax -- without that syntax, you can't access it.
But in the use cases where you'd actually want to make such a function
return a value to begin with, it's because that value is the value you
*really* want from the function -- the only reason it's a generator is
because it needs to be paused and resumed along the way to getting
that return value.
How about if 'yield from' returns the generator object, and the return
value is accessed with an attribute.
g = yield from gen
x = g.__value__
Or
x = (yield from gen).__value__
Another possibility is to be able to break from a 'yield from' at some
point and then continue it to get any final values.
# yield values of sub generator
g = yield from gen
# get remaining unused value of sub generator
x = g.next()
This could possibly be done in one line as well...
x = (yield from gen).next()
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com