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

Masklinn masklinn at masklinn.net
Wed Nov 30 14:55:46 CET 2011


On 2011-11-30, at 14:32 , Giampaolo Rodolà wrote:
> This is problably too late and I'm probably missing something but
> given amount of generators/iterators introduced in python 3.X
> (http://docs.python.org/release/3.0.1/whatsnew/3.0.html#views-and-iterators-instead-of-lists)
> file.readlines() seems a good case where an iterator can be more
> appropriate than a list.
Iterating on the file itself already iterates by line, what would be the value of doing it *again* for readlines()? The sizehint?

Note how file objects *used* to have a `xreadlines()` method which was deprecated (and removed in Python3) in favor of iterating the file object directly.




More information about the Python-ideas mailing list