<div dir="ltr"><br><div class="gmail_quote">On Wed, Nov 30, 2011 at 15:32, Giampaolo Rodolà <span dir="ltr"><<a href="mailto:g.rodola@gmail.com">g.rodola@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
This is problably too late and I'm probably missing something but<br>
given amount of generators/iterators introduced in python 3.X<br>
(<a href="http://docs.python.org/release/3.0.1/whatsnew/3.0.html#views-and-iterators-instead-of-lists" target="_blank">http://docs.python.org/release/3.0.1/whatsnew/3.0.html#views-and-iterators-instead-of-lists</a>)<br>
file.readlines() seems a good case where an iterator can be more<br>
appropriate than a list.<br>
I realized it while writing this recipe:<br>
<a href="http://code.activestate.com/recipes/577968-log-watcher-tail-f-log/" target="_blank">http://code.activestate.com/recipes/577968-log-watcher-tail-f-log/</a><br>
In this specific case, having readlines() yield a single line at a<br>
time would save a lot of memory.<br>
Maybe we can introduce a new parameter to do this?<br></blockquote></div><br>Giampaolo, perhaps I'm missing something, but what's bad about having a generator instead:<br><br>linesgen = (line for line in file)<br>
<br>You'd basically now do with linesgen whatever you wanted to do with an iterator-returning file.readlines()<br><br>Eli<br><br><br><br></div>