I am getting an odd problem. when I am trying to replace a string in a file. The relevant line in the file is:
lattice parameter A [a.u.] 5.771452243459 and I am trying to replace it as:
with open(newsys, "r+") as finp: for line in finp: # print(line) if line.startswith("lattice parameter A [a.u.]"): line = next(finp) print(line) print(Alat) line.replace(line.strip(), str(Alat)) print(line) the last 3 print statement gives:
5.771452243459 # string that will be replaced 6.63717007997785 #value of Alat 5.771452243459 #the line after replace statement What is going wrong here?