writing large files quickly
Tim Chase
python.list at tim.thechases.com
Fri Jan 27 14:24:48 EST 2006
> Untested, but this should be faster.
>
> block = '0' * 409600
> fd = file('large_file.bin', 'wb')
> for x in range(1000):
> fd.write('0')
> fd.close()
Just checking...you mean
fd.write(block)
right? :) Otherwise, you end up with just 1000 "0" characters in
your file :)
Is there anything preventing one from just doing the following?
fd.write("0" * 409600000)
It's one huge string for a very short time. It skips all the
looping and allows Python to pump the file out to the disk as
fast as the OS can handle it. (and sorta as fast as Python can
generate this humongous string)
-tkc
More information about the Python-list
mailing list