Iterator class to allow self-restarting generator expressions?
metolone+gmane at gmail.com
Sun Mar 1 17:39:46 CET 2009
"John O'Hagan" <research at johnohagan.com> wrote in message
news:200903011520.29405.research at johnohagan.com...
> Inspired by some recent threads here about using classes to extend the
> behaviour of iterators, I'm trying to replace some some top-level
> aimed at doing such things with a class.
> So far it's got a test for emptiness, a non-consuming peek-ahead method,
> an extended next() which can return slices as well as the normal mode, but
> one thing I'm having a little trouble with is getting generator
> to restart when exhausted. This code works for generator functions:
The Python help shows the Python-equivalent code (or go to the source) for
things like itertools.islice and itertools.icycle, which sound like what you
are re-implementing. It looks like to handle generators icycle saves the
items as they are generated in another list, then uses the list to generate
More information about the Python-list