writing large files quickly

Grant Edwards grante at visi.com
Fri Jan 27 21:03:44 CET 2006


On 2006-01-27, Tim Chase <python.list at tim.thechases.com> wrote:
>>>     fd.write('0')
> [cut]
>> 
>> f = file('large_file.bin','wb')
>> f.seek(409600000-1)
>> f.write('\x00')
>
> While a mindblowingly simple/elegant/fast solution (kudos!), the 
> OP's file ends up with full of the character zero (ASCII 0x30), 
> while your solution ends up full of the NUL character (ASCII 0x00):

Oops.  I missed the fact that he was writing 0x30 and not 0x00.

Yes, the "hole" in the file will read as 0x00 bytes.  If the OP
actually requires that the file contain something other than
0x00 bytes, then my solution won't work.

-- 
Grant Edwards                   grante             Yow!  I want the presidency
                                  at               so bad I can already taste
                               visi.com            the hors d'oeuvres.



More information about the Python-list mailing list