[perl-python] 20050121 file reading & writing
Bob Smith
bob_smith_17280 at hotmail.com
Sun Jan 23 18:53:35 EST 2005
Erik Max Francis wrote:
> Bob Smith wrote:
>
>> To do this efficiently on a large file (dozens or hundreds of megs),
>> you should use the 'sizehint' parameter so as not to use too much memory:
>>
>> sizehint = 0
>> mylist = f.readlines(sizehint)
>
>
> It doesn't make any difference. .readlines reads the entire file into
> memory at once.
>
Are you sure, the docs say this:
"f.readlines() returns a list containing all the lines of data in the
file. If given an optional parameter sizehint, it reads that many bytes
from the file and enough more to complete a line, and returns the lines
from that. This is often used to allow efficient reading of a large file
by lines, but without having to load the entire file in memory. Only
complete lines will be returned."
http://docs.python.org/tut/node9.html
More information about the Python-list
mailing list