通过脚本传参数可以实现替换
# -*-coding:utf-8-*- # Author:sunhao import sys f = open(‘yesterday‘,‘r‘,encoding=‘utf-8‘) f_new = open(‘yesterday.bak‘,‘w‘,encoding=‘utf-8‘) find_str=sys.argv[1] replace_str=sys.argv[2] for line in f: if "肆意的快乐" in line: line=line.replace(find_str,replace_str) f_new.write(line) f.close() f_new.close()
时间: 2024-10-11 10:48:37