Can I change one line in a file without rewriting the whole thing?

J. J. Ramsey jjramsey at pobox.com
Sat Jul 14 04:46:24 CEST 2007


In Perl, there is a module called "Tie::File". What it does is tie a
list to each line of a file. Change the list, and the file is
automatically changed, and on top of this, only the bits of the file
that need to be changed are written to disk. At least, that's the
general idea.

I was wondering if something roughly similar could be done in Python,
or at the very least, if I can avoid doing what amounts to reading the
whole file into memory, changing the copy in memory, and writing it
all out again.




More information about the Python-list mailing list