A bundle of questions from a Python newbie
Paul Rubin
phr-n2002a at nightsong.com
Thu Feb 21 06:22:02 EST 2002
Duncan Booth <duncan at NOSPAMrcp.co.uk> writes:
> The main differences between a coroutine and a generator are:
>
> 1) Coroutines maintain their own stack. This allows a coroutine to yield
> not just from the function you originally called, but also from any nested
> function no matter how deep.
> Python's generators can only yield directly from the generator as they do
> not attempt to maintain any kind of stack.
Is that right? I thought the classic coroutine example is supposed to
also work with generators:
def traverse(tree):
if tree.left: traverse(tree.left)
yield tree.value
if tree(right) traverse(tree.right)
Am I missing something?
More information about the Python-list
mailing list