[PIPython] xreadlines()

Lawrence Oluyede l.oluyede
Ven 19 Nov 2004 15:16:46 CET


> Qualcuno sà dirmi il motivo per cui
> il metodo file.xreadlines() è deprecated since 2.3 ??

Perchè sono i file sono iteratori e sono più efficienti

>   e dicono di usare  "for line in file:"   ???

http://www.strakt.com/docs/ep03_py23.pdf

e direttamente da http://docs.python.org/whatsnew/node17.html

"The xreadlines() method of file objects, introduced in Python 2.1, is
no longer necessary because files now behave as their own iterator.
xreadlines() was originally introduced as a faster way to loop over
all the lines in a file, but now you can simply write for line in
file_obj. File objects also have a new read-only encoding attribute
that gives the encoding used by the file; Unicode strings written to
the file will be automatically converted to bytes using the given
encoding."



More information about the Python mailing list