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

Guido van Rossum guido@python.org
Thu, 18 Jul 2002 15:18:38 -0400


> > I've just had a thought. Maybe it would be less of a mess
> > if what we are calling "iterators" had been called "streams"
> 
> Possibly -- I did use the "streams" name often in the tutorial
> on iterators and generators, it's a very natural term.

OTOH in C++ and Java, "stream" refers to an open file object (to
emphasize the iteratorish feeling of a file opened for sequential
reading or writing, as opposed to the concept of a file as a
random-access array of bytes on disk).

> Seekable files can be multi-pass, but in the strict sense
> that you can rewind them -- it's still impractical to have
> them produce multiple *independent* iterators (needing
> some sort of in-memory caching).

It would be trivial if you had an object representing the notion of a
file on disk rather than an open file.  Each iterator would be
implemented as a separate open file referring to the same filename.

--Guido van Rossum (home page: http://www.python.org/~guido/)