[Python-ideas] Revised**12 PEP on Yield-From
Erik Groeneveld
erik at cq2.org
Fri Apr 24 13:27:30 CEST 2009
Greg,
2009/4/24 Greg Ewing <greg.ewing at canterbury.ac.nz>:
> Seems to me you could yield a sequence of values
> to be pushed back, and use a top-level driver
> something like this:
>
> def pushingback(g):
> queue = []
> try:
> while 1:
> queue.append(yield)
> while queue:
> pushback = g.send(queue.pop(0))
> if pushback:
> queue.extend(pushback)
> except StopIteration, e:
> return e.value
Great. I think this is gonna work as a top level driver and I'll work
it out. Thanks!
> So when seeing the generator send/yield mechanism for
> the first time, it's tempting to think of it as being
> like sending data to a process through a pipe. But
> it's not really like that -- it's a lower-level
> facility.
I regret I apparently didn't raise your interest in mapping JSP onto
Python coroutines. If you ever get sick of queues, buffers and
callbacks, give it a try!
Thanks so far, I look forward to the definite implementation of your PEP.
--Erik
More information about the Python-ideas
mailing list