Aug-15-2019, 05:22 PM
(This post was last modified: Aug-15-2019, 05:50 PM by ichabod801.)
Hi,
I have wrote and trying to implement the code. I want to replace the whole lline containing anything like mov9, inp9 etc.
Please help me.
I have wrote and trying to implement the code. I want to replace the whole lline containing anything like mov9, inp9 etc.
filename = 'myfile.txt' with open(filename, 'r') as f: text = f.read() text = text.replace('mov9=', 'mov9=this is') text = text.replace('inp9=go', 'nom') text = text.replace('nin9', 'ten9=pop') with open(filename, 'w') as f: f.write(text)when I run the code..I got the output like 'mov9=this is' first time. But second time I got like' mov9=this is this is'. I just want to replace the whole line containing move9 or inp9 everytime.
Please help me.