📌  相关文章
📜  python 查找和替换文件中的字符串 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:44.441000             🧑  作者: Mango

代码示例2
#input file
fin = open("data.txt", "rt")
#output file to write the result to
fout = open("out.txt", "wt")
#for each line in the input file
for line in fin:
    #read replace the string and write to output file
    fout.write(line.replace('pyton', 'python'))
#close input and output files
fin.close()
fout.close()