Generators versus Coroutines

Timothy Fitz firemoth at gmail.com
Sat Aug 14 14:32:22 EDT 2004


It seems to me that in python, generators are not truly coroutines. I
do not understand why. What I see is that generators are used almost
exclusively for generation of lists just-in-time. Side effects are
frowned upon. Coroutines, in contrast, are like split functions where
side effects are often as important or more important than return
values. I am currently writing a real time strategy game where I have
visual effects and use generators as coroutines which yield after
processing a single frame of the effect. I can easily make an object
rotate indefinitely with a scant four or five lines of code, all of
which is in one place. So knowing that the difference between a
generator and a coroutine is minor, I come (in a very roundabout way)
to my issue. Why can I use "return" without an expression and it
implicitly returns None but I can't do the same thing with "yield" ?



More information about the Python-list mailing list