How do I search and replace text in a file using Python 3?
Here is my code:
import os import sys import fileinput print (\"Text to search for:\") te
Late answer, but this is what I use to find and replace inside a text file:
with open("test.txt") as r: text = r.read().replace("THIS", "THAT") with open("test.txt", "w") as w: w.write(text)
DEMO