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()
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4