Use the replace()
to replace the text, for example:
newTxt = txt.replace('#what word you want to repalce', '# which word you want to replace it with')
and this code will make the text file replace and save:
#input file
test = open("Test.txt", "w+")
#output file to write the result to
test2 = open("Test2.txt", "wt")
#for each line in the input file
for line in test:
#read replace the string and write to output file
test2.write(line.replace('replace', 'replaced'))
#close input and output files
test.close()
test2.close()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…