replace string in a file

sturlamolden sturlamolden at yahoo.no
Sun Mar 16 22:35:22 EDT 2008


On 15 Mar, 21:54, Unknown <cantabile... at wanadoo.fr> wrote:

> I was expecting to replace the old value (serial) with the new one
> (todayVal). Instead, this code *adds* another line below the one found...
>
> How can I just replace it?

A file is a stream of bytes, not a list of lines. You can't just
replace a line with another, unless they have the exact same length.
You must rewrite the whole file to get it right.





More information about the Python-list mailing list