直接上代码:
1 2 3 4 5 6 7 8 9 10 11 12 |
with open("./test.txt","r",encoding="utf-8") as f: lines = f.readlines() with open("./fileread.txt","w",encoding="utf-8") as f_w: for line in lines: if "taste" in line: line = line.replace("taste","tasting") f_w.write(line) |
思想:
读一行写一行。
本文最后更新于2022年10月31日,已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!