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
You can also use pathlib.
pathlib
from pathlib2 import Path path = Path(file_to_search) text = path.read_text() text = text.replace(text_to_search, replacement_text) path.write_text(text)