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

Terry Reedy tjreedy at udel.edu
Fri Dec 2 22:55:23 CET 2011

On 12/2/2011 4:02 PM, Matthew Woodcraft wrote:
> On 2011-11-30 13:59, Peter Otten wrote:
>> My observation on the Tutor mailing list is that there are no valid uses of
>> readlines(). It's just easier to discover the readlines() method than to
>> find out that you can iterate over the file directly.
> In 2.x, iterating directly can behave unexpectedly if the file object is
> something other than a regular file; see eg
> http://bugs.python.org/issue1633941
> http://bugs.python.org/issue3907

Both are fixed in 3.x

> http://utcc.utoronto.ca/~cks/space/blog/python/FileIteratorProblems
> readline() and readlines() don't have these problems.
> -M-

Terry Jan Reedy

More information about the Python-ideas mailing list