[Python-ideas] Possible PEP 380 tweak
Ron Adam
rrr at ronadam.com
Fri Oct 29 07:53:24 CEST 2010
On 10/28/2010 08:17 PM, Nick Coghlan wrote:
> def average_sums():
> # Advances to a new sum when EndSum is thrown in
> # Finishes the last sum and averages them all when GeneratorExit
> is thrown in
> sums = []
> try:
> while 1:
> sums.append(yield from gsum())
Wouldn't this need to be...
gsum_ = gsum()
next(gsum_)
sums.append(yield from gsum_)
Or does the yield from allow send on a just started generator?
> except GeneratorExit as ex:
> # Our proposed expansion tweak is to enable the next line
> sums.append(ex.args[0])
> return sum(sums) / len(sums)
Ron
More information about the Python-ideas
mailing list