iterating over lines in a file

Cliff Crawford cjc26 at nospam.cornell.edu
Sun Jul 23 21:07:07 EDT 2000


* Tim Peters <tim_one at email.msn.com> menulis:
| 
| > Ugh, you're right (I checked fileobject.c to make sure).  That makes
| > readlines() a lot less useful than I thought it was..:(
| 
| How so?  It *can't* take the size argument exactly as given, lest it return
| a partial line at the end of the returned list more often than not.  Most
| people would consider it "a lot less useful" then <wink>.

No, what I meant was that I thought readlines() always reads the entire
file, whether you specify a size argument or not, and so if you were
worried about "for line in file.readlines():" eating too much memory,
you could just do "for line in file.readlines(8192):" instead, and it
would read the entire file using only an 8k buffer.  At least, that's
what I thought the library reference was saying..but the source code
proved me wrong :)

I do agree, though, that the current behavior of readlines() is quite
useful for it's >intended< purpose ;)


-- 
cliff crawford    -><-    http://www.people.cornell.edu/pages/cjc26/
                          Synaesthesia now!            icq 68165166



More information about the Python-list mailing list