0 search replace files in python - smart1004/ReadTheDocs GitHub Wiki

https://stackoverflow.com/questions/17140886/how-to-search-and-replace-text-in-a-file-using-python

filein='./file.txt' f = open(filein,'r') filedata = f.read() f.close()

old_data =
"""aaa bbb"""

new_data = "aaa bbb"

newdata = filedata.replace(old_data, new_data)

fileout='./fileout.txt' f = open(fileout,'w') f.write(newdata) f.close()