A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2002-July/026647.html below:

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

[Python-Dev] Single- vs. Multi-pass iterabilityGuido van Rossum guido@python.org
Wed, 17 Jul 2002 14:30:09 -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?

I think that Oren's patch would make this work (the iterator requested
by the second for loop would return the same iterator as the first
one, since it's cached in the file object), but at the cost of an
unbreakable cycle between the file and the xreadlines object.

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




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4