supercheetah
February 15th, 2009, 12:33 PM
I'm trying to learn Python, but I am running into a "writer's block" of sorts, or maybe I've been too corrupted by C++, or maybe I just don't know Python well enough. I'm not sure which.
Anyway, I have a question about a file that I have open in read/write mode so that I can replace certain values in it:
targetfile = open(targetname, "r+")
Some of the values in the file that I'm trying to replace are longer than the values I'm trying to replace them with. In other words, let's say I'm trying to replace "foobar\n" with just "foo\n" in the targetfile. I can't figure out for the life of me what I need to do to get rid of the extra three characters. I tried using '\b', but that just gave me garbage that would show up as "foo^H^H^H".
Argh! What am I missing? :confused:
Anyway, I have a question about a file that I have open in read/write mode so that I can replace certain values in it:
targetfile = open(targetname, "r+")
Some of the values in the file that I'm trying to replace are longer than the values I'm trying to replace them with. In other words, let's say I'm trying to replace "foobar\n" with just "foo\n" in the targetfile. I can't figure out for the life of me what I need to do to get rid of the extra three characters. I tried using '\b', but that just gave me garbage that would show up as "foo^H^H^H".
Argh! What am I missing? :confused: