I want to open a txt file and replace all "hello" to "love" and save it and do not create a new file. Just modify the content in the same txt file.
My code just can add "love" after "hello", rather than substitute them.
Any method can fix it?
Thx so much
f = open("1.txt",'r+')
con = f.read()
f.write(re.sub(r'hello','Love',con))
f.close()