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

Guido van Rossum guido at python.org
Wed Nov 30 16:54:11 CET 2011


On Wed, Nov 30, 2011 at 6:31 AM, Yuval Greenfield <ubershmekel at gmail.com>wrote:

> Since we marginally brushed the subject of backwards compatibility
> damning...
>
> I'm kind of surprised that files do that. Now that I check I'm surprised
> that StringIO does that.
>
> text = 'asdf\nword'
> for item in StringIO(text):    !=    for item in text:
>
> I'm not sure if I like that.
>

We thought about that. Really. We concluded that while iterating over the
characters of a file would be more "pure" but that it would rarely be
useful, while iterating over the files would be incredibly useful. That was
probably about 10 years ago, and I still think we made the right decision.

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20111130/6f194658/attachment.html>


More information about the Python-ideas mailing list