reseting an iterator

Jan jan.plaza at
Wed May 20 20:48:07 CEST 2009

On May 20, 2:35 pm, Jan < at> wrote:

OOPS, I have pressed some keys and the message went out before It was
Here is the last fragment:

So, one can define iterators by defining a class whose objects have
__iter__ and __next__ -- with this approach it is easy to add some
method. But the easiest way to define iterators is by constructing a
function (with yield expressions); this function returns iterators,
without __reset__. Another way to define an iterator is to define
and using iter(CALLABLE, SENTINEL) -- the resulting iterator will not
have __reset__.
I do not know how Python is implemented but I believe that
in the last two cases, Python could produce improved iterators with
at almost no additional cost.


More information about the Python-list mailing list