文件替换轻量版
#!-*- coding:utf-8 -*-
import sys
find_str = input("你想修改什么:")
replace_str = input("改为什么:")
with open("yesday.txt","r",encoding="utf-8") as f,\
open("yesday.bak","w",encoding="utf-8") as f_new:
for line in f:
if find_str in line:
line = line.replace(find_str,replace_str)
f_new.write(line)
f_new.flush()
f.close()
f_new.close()