#字符串替换import sysf = open("yesterday2","r",encoding="utf-8")f_new = open("yesterday2.bak","w",encoding="utf-8") find_str = sys.argv[1]replace_str = sys.argv[2]for line in f: if find_str in line: line = line.replace(find_str,replace_str) f_new.write(line)f.close()f_new.close() #with执行问了,文件就自动关闭了! 开发规范一行代码不能超过80字符: \
with open("yesterday2","r",encoding="utf-8") as f ,\ open("yesterday2", "r", encoding="utf-8") as f2: for line in f: print(line)
原文地址:https://www.cnblogs.com/wzsx/p/8969775.html
时间: 2024-10-12 17:01:33