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

Guido van Rossum guido@python.org
Fri, 12 Jul 2002 08:46:26 -0400


> I have just submitted a patch that makes a file into an iterator
> (i.e. adds a .next method to files).  With this change all Python
> objects that have an __iter__ method and no next method produce
> iterators that do not modify the container.  Another possibility
> would be to make file iterators that use seek or re-open the file to
> avoid modifying the file position of the parent file object.  I
> don't think that would be a good idea because files can be devices,
> pipes or sockets which are not seekable.

Cute trick, but I think it's too fragile.  You don't know about 3rd
party iterables that have the same problem as file.

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