Writing to a certain line?

Rene Pijlman reply.in.the.newsgroup at my.address.is.invalid
Tue Jun 6 04:46:49 EDT 2006


Tommy  B:
>I was wondering if there was a way to take a txt file and, while
>keeping most of it, replace only one line.

You'd need to read the file and parse it, to find the start position of
the line you want to change. Then seek output to that position and write
and flush the changes. You must keep the file locked during this
operation, to prevent other processes from changing the file in between
these steps. You can only replace a string with a string of the same
length.
http://docs.python.org/lib/bltin-file-objects.html

-- 
René Pijlman



More information about the Python-list mailing list