标签:blog tmp 配置 实现 file write replace pytho sed
#可以用来修改配置文件参数
1 # -*- coding:utf-8 -*- 2 import os,sys 3 old = sys.argv[1] 4 new = sys.argv[2] 5 file = sys.argv[3] 6 file2 = sys.argv[3] 7 tmp_file ="tmpfile" 8 f = open(file,"r") 9 f2 = open(tmp_file,"r+") 10 for line in f: 11 if old in line: 12 line= str.replace(line,old,new) 13 f2.write(line) 14 f2.write(line) 15 f2.flush() 16 f.close() 17 f2.close() 18 19 os.remove(file) 20 os.rename(tmp_file,file2)
标签:blog tmp 配置 实现 file write replace pytho sed
原文地址:http://www.cnblogs.com/liruixin/p/5992301.html