writing large files quickly

Tim Chase python.list at tim.thechases.com
Fri Jan 27 14:45:20 EST 2006


>>     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):

   tkc at oblique:~/temp$ xxd op.bin
   0000000: 3030 3030 3030 3030 3030       0000000000
   tkc at oblique:~/temp$ xxd new.bin
   0000000: 0000 0000 0000 0000 0000       ..........

(using only length 10 instead of 400 megs to save time and disk 
space...)

-tkc








More information about the Python-list mailing list