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

Matthew Woodcraft matthew at woodcraft.me.uk
Fri Dec 2 22:02:05 CET 2011

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

readline() and readlines() don't have these problems.


More information about the Python-ideas mailing list