Cannot get variable.replace working properly.
Posted
by chrissygormley
on Stack Overflow
See other posts from Stack Overflow
or by chrissygormley
Published on 2010-06-14T15:57:15Z
Indexed on
2010/06/14
16:12 UTC
Read the original article
Hit count: 125
Hello,
I am trying to replace a string with a new string in a python file and write the new string permanently to it. When I run the below script it removes part of the string and not all of it. The string in the file is:
self.id = "027FC8EBC2D1"
And the script I have to replace the string is:
def edit():
o = open("test.py","r+") #open
for line in open("test.py"):
line = line.replace("027FC8EBC2D1","NewValue")
o.write(line)
o.close()
edit()
Thanks for any help.
© Stack Overflow or respective owner