How does a generator object refer to itself?

Russell russell_turpin at hotmail.com
Mon May 22 11:17:49 EDT 2006


This is more a Python 2.5 question, since it is the send()
method that makes this so useful. The issue is how to write
a generator that refers to its own generator object. This
would be useful when passing control to some other function
or generator that is expected to return control via a send():

def me():
    ..
    nextVal = yield you(me.send)        # This is wrong!

That almost looks right, except that "me" isn't really the
generator object that is executing, it is the function that
produces the generator object. It seems somewhere I read
that some keyword ("generator"?) would work in this context,
but now I can't find where I read that. Maybe I imagined it.

Thanks!




More information about the Python-list mailing list