On 2006-09-02, Dasn <[EMAIL PROTECTED]> wrote: > Hi. > Suppose we have a very large file, and wanna remove 'n' bytes in the > middle of the file. My thought is: > 1, read() until we reach the bytes should be removed, and mark the > position as 'pos'. > 2, seek(tell() + n) bytes > 3, read() until we reach the end of the file, into a variable, say 'a' > 4, seek(pos) back to 'pos' > 5, write(a) > 6, truncate() > > If the file is really large, the performance may be a problem. > Is there a clever way to finish? Could mmap() help? Thx
Instead of reading till the end of the file in step 3, do it a chunk at a time in a loop. -- Grant Edwards grante Yow! I'm gliding over a at NUCLEAR WASTE DUMP near visi.com ATLANTA, Georgia!! -- http://mail.python.org/mailman/listinfo/python-list