Restart generator when it is exhausted.
Lacrima.Maxim at gmail.com
Tue Apr 28 12:39:23 CEST 2009
On Apr 28, 1:04 pm, Chris Rebert <c... at rebertia.com> wrote:
> On Tue, Apr 28, 2009 at 2:54 AM, Lacrima <Lacrima.Ma... at gmail.com> wrote:
> > Hello!
> > I am quite new to Python and I have maybe simple (or maybe not)
> > question.
> > Is it possible to restart generator when it is exhausted?
> No. You have to make a new instance of the generator.
> > What should I do to get the initial state of g? So if I do again g.next
> > () I receive 'a'.
> g = (i for i in a) #that is, make a fresh generator instance
> > If it is not possible what are common techniques to use iterator or
> > generator objects that allow restarting when it is needed?
> There's itertools.cycle() --http://docs.python.org/library/itertools.html#itertools.cycle
Chris, thanks a lot for the help!
More information about the Python-list