Writing to a certain line?
Fredrik Lundh
fredrik at pythonware.com
Tue Jun 6 17:58:10 EDT 2006
Tommy B wrote:
>> import os
>> old = open("/path/to/file.txt", "r")
>> new = open("/path/to/new.txt", "w")
>> for line in old:
>> if line.strip() == "Bob 62"
>> line = line.replace("62", "66")
>> new.write(line)
>> old.close()
>> new.close()
>> os.rename("/path/to/new.txt", "/path/to/file.txt")
> Umm... I tried using this method and it froze. Infiinite loop, I'm
> guessing.
you have an infinitely large disk with an infinitely large file on it?
</F>
More information about the Python-list
mailing list