• Guido van Rossum's avatar
    SF patch 580331 by Oren Tirosh: make file objects their own iterator. · 7a6e9594
    Guido van Rossum yazdı
    For a file f, iter(f) now returns f (unless f is closed), and f.next()
    is similar to f.readline() when EOF is not reached; however, f.next()
    uses a readahead buffer that messes up the file position, so mixing
    f.next() and f.readline() (or other methods) doesn't work right.
    Calling f.seek() drops the readahead buffer, but other operations
    don't.
    
    The real purpose of this change is to reduce the confusion between
    objects and their iterators.  By making a file its own iterator, it's
    made clearer that using the iterator modifies the file object's state
    (in particular the current position).
    
    A nice side effect is that this speeds up "for line in f:" by not
    having to use the xreadlines module.  The f.xreadlines() method is
    still supported for backwards compatibility, though it is the same as
    iter(f) now.
    
    (I made some cosmetic changes to Oren's code, and added a test for
    "file closed" to file_iternext() and file_iter().)
    7a6e9594
Adı
Son kayıt (commit)
Son güncelleme
Demo Loading commit data...
Doc Loading commit data...
Grammar Loading commit data...
Include Loading commit data...
Lib Loading commit data...
Mac Loading commit data...
Misc Loading commit data...
Modules Loading commit data...
Objects Loading commit data...
PC Loading commit data...
PCbuild Loading commit data...
Parser Loading commit data...
Python Loading commit data...
RISCOS Loading commit data...
Tools Loading commit data...
.cvsignore Loading commit data...
.hgtags Loading commit data...
LICENSE Loading commit data...
Makefile.pre.in Loading commit data...
PLAN.txt Loading commit data...
README Loading commit data...
configure Loading commit data...
configure.in Loading commit data...
install-sh Loading commit data...
pyconfig.h.in Loading commit data...
setup.py Loading commit data...