[Python-ideas] Is there a reason why file.readlines() doesn't/can't return an iterator?

Éric Araujo merwok at netwok.org
Wed Nov 30 16:51:27 CET 2011


Le 30/11/2011 14:59, Peter Otten a écrit :
> My observation on the Tutor mailing list is that there are no valid
> uses of readlines().
I disagree :)  You don’t always read big files, or you may prefer to
close the file handle early at the cost of memory, or you need a list to
do some processing that works with lists but not iterators.  FWIW, I use
readlines a lot to get list of lines for unit tests, for example (in
case of failure, lists make better diffs than strings).

> So my counter-proposal is to remove the readlines method but to leave the 
> corresponding entry in the documentation with a a description of the "right 
> way" to iterate over the lines of a file.
A doc entry for a non-existing function would be very confusing.

> Backwards compatibility be damned ;)
Not sure what the smiley means; compatibility is taken seriously, and
removing things has a very high bar.

Cheers



More information about the Python-ideas mailing list