[Python-ideas] Is there a reason why file.readlines() doesn't/can't return an iterator?
Stephen J. Turnbull
stephen at xemacs.org
Thu Dec 1 02:38:21 CET 2011
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.
More information about the Python-ideas
mailing list