python 修改文件

import os
f1 = open("user.txt",encoding='utf-8')
f2 = open("user.txt.bak","w",encoding="utf-8")
for line in f1:
new_line = line.replace("周","周杰伦")
f2.write(new_line)
f1.close()
f2.close()
os.remove("user.txt")
os.rename("user.txt.bak","user.txt")
上一篇:上下文管理器


下一篇:VC模拟发送数据包-百度关键词查找