I am trying to operate some file like this:
*sline
1, 1.0, 2.23
2, 1.0, 9.98
3, 2.0, 10.00
*eline
Now I have a list, which contain data like this:
datalist = [[1,1.0,2.0],[3,2.0,2.0]]
I want to put the value which belong to datalist to replace the value in the file by id(datalist[][0]), like:
*sline
1, 1.0, 2.0
2, 1.0, 9.98
3, 2.0, 2.0
*eline
I am try to utilse:
o = open("file","a")
for line in open("trychange.txt"):
line = line.replace("1, 1.0, 2.23","1, 1.0, 2.0")
line = line.replace("3, 2.0, 10.00","3, 2.0, 2.0")
o.write(line + "\n")
o.close()
but it doesn't work, it just add new values but didn't change the old one. how can I deal with this? Thanks for your helping