I am trying to delete one line of code from a text file and update it to a new value.
I have user inputted value in "line1" and "line2" and trying to update value of line1 to line2. When I used below code,
f1=open("test.txt","a+")
f2=open("test.txt","a+")
for line in f1:
f2.write(line.replace(line1,line2))
f1.close()
f2.close()
It doesn't replace the value of line1 to line2 but creates another line of line2. So output in my text file is value of line1 value of line2
How can I change this code to replace the value of line1 to line2 and delete the value of line1 from the text file?
Thanks!