[Python-Dev] Single- vs. Multi-pass iterability
Andrew Koenig
ark@research.att.com
17 Jul 2002 14:08:50 -0400
Guido> Likewise, the file needs a strong ref to the xreadlines,
Guido> otherwise the following would create a new iterator in the
Guido> second for loop, and lose data buffered by the first iterator.
Guido> f = open(filename)
Guido> it = iter(f)
Guido> for i in range(10):
Guido> it.next()
Guido> del it
Guido> for line in f:
Guido> print line,
Guido> I think I will have to reject Oren's patch because of this, and
Guido> the situation with file iterators will remain as it is: once
Guido> you've asked for the iterator, all operations on the file are
Guido> unsafe, and the only way to get back to using the file is to
Guido> abandon the file and do an absolute seek on the file.
This implies that you don't expect the code above to work correctly, right?
--
Andrew Koenig, ark@research.att.com, http://www.research.att.com/info/ark