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
Like so:
def find_and_replace(file, word, replacement): with open(file, 'r+') as f: text = f.read() f.write(text.replace(word, replacement))