creating/modifying sparse files on linux

draghuram at gmail.com draghuram at gmail.com
Wed Aug 17 14:53:39 EDT 2005


Hi,

Is there any special support for sparse file handling in python? My
initial search didn't bring up much (not a thorough search). I wrote
the following pice of code:

options.size = 6442450944
options.ranges = ["4096,1024","30000,314572800"]
fd = open("testfile", "w")
fd.seek(options.size-1)
fd.write("a")
for drange in options.ranges:
    off = int(drange.split(",")[0])
    len = int(drange.split(",")[1])
    print "off =", off, " len =", len
    fd.seek(off)
    for x in range(len):
    fd.write("a")

fd.close()

This piece of code takes very long time and in fact I had to kill it as
the linux system started doing lot of swapping. Am I doing something
wrong here? Is there a better way to create/modify sparse files?

Thanks,
Raghu.




More information about the Python-list mailing list