Reset a generator function?

Terry Reedy tjreedy at
Tue Sep 10 16:40:46 EDT 2002

"Robert Oschler" <Oschler at> wrote in message
news:%Lrf9.30107$w51.7961593 at
> How can I reset a generator function so that it begins yielding
values as it
> did when first called?

The generator function does not really yield values.  It returns an
iterator that yields values.  This is handled transparently by the for
loop mechanism.  The iterator cannot be reset.  The generator can be
called again, with either the same or different arguments, to return a
new iterator that will yield the same or different sequence.  It can
even be called again before you use the first iterator to get any

Terry J. Reedy

More information about the Python-list mailing list