[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 04:13:03 CET 2011

On 11/30/2011 8:38 PM, Stephen J. Turnbull wrote:
> Peter Otten writes:
>   >  Éric Araujo wrote:
>   >
>   >  >  Okay.  You can open a report on bugs.python.org to ask that the doc for
>   >  >  readlines mention list(fp) as an alternative.
>   >
>   >  That would make sense to me only if readlines() were deprecated.
> It makes sense to me.  Something like
>      Note that "for line in fp:" (to iterate over the lines of the
>      file) and "list(fp)" (to get a list of all lines in a file) are
>      idiomatic Python.
> to remind readers (especially new users) of the iterator concept,
> which is even today not so familiar to beginning programmers.

See http://bugs.python.org/issue13510 ,
where I suggested something like that.

Terry Jan Reedy

More information about the Python-ideas mailing list