import sys
find_str=sys.argv[1]
replace_str=sys.argv[2]
with open('test.txt','r') as f:
with open('test1.txt','w') as f2:
for line in f:
if find_str in line:
line=line.replace(find_str,replace_str)
f2.write(line)
用法:
效果:
替换前
替换后