[Python-Dev] Single- vs. Multi-pass iterability

David Abrahams David Abrahams" <david.abrahams@rcn.com
Tue, 9 Jul 2002 04:43:25 -0400


From: "Oren Tirosh" <oren-py-d@hishome.net>
>
> I believe that when David was talking about multi-pass iterability he
> wasn't referring to an iterator that can be told to "start over again"
but
> to an iterable object that can produce multiple independent iterators of
> itself, each one good for a single iteration.

That's right.

> The language does make a distinction between an *iterable* object that
may
> have only an __iter__ method and an *iterator* that has a next method.
This
> distinction is blurred a bit by the fact that iterators also have an
> __iter__ method that also makes them appear as one-shot iterables.

Yep. [Part of the reason I want to know whether I've got a one-shot
sequence is that inspecting that sequence then becomes an
information-destroying operation -- only being able to touch it once
changes how you have to handle it]

I was thinking one potentially nice way to introspect about
multi-pass-ability might be to get an iterator and to see whether it was
copyable. Currently even most multi-pass iterators can't be copied with
copy.copy().

-Dave