replacing lines in a file

MRAB python at mrabarnett.plus.com
Thu Jan 27 21:38:44 EST 2011


On 28/01/2011 00:58, mpnordland wrote:
> thanks for explaining what I was doing wrong and how reading the file
> works. What would you suggest I do to remedy the situation?
>
Write the new config out to a new file and then replace the old file
with the new file. I'd use shutil.move(...) to do the replacement.
This means that the existing config file will remain unchanged until
you've successfully created the new config file (it's somewhat annoying
if you're modifying a file and there's an exception part way through
due to a bug, leaving 'invalid' contents!)



More information about the Python-list mailing list