python 替换文本,,'''Created o
文章由Byrx.net分享于2019-03-23 08:03:19
python 替换文本,,'''Created o
'''Created on 2013-3-16@author: WJH'''#-*- coding: utf-8 -*-import sysimport osimport getoptimport timeopts, args = getopt.getopt(sys.argv, 'hvo:', ['output=', 'foo=', 'fre=']);print opts;print args;#ganglia file pathgmondFile = 'C:\\\\WINDOWS\\\\Ganglia\\\\gmond.conf'logFile = 'c:\\\\gmond.log'#log filelog = open(logFile,"w")oldConfigFile = open(gmondFile,"r")#store old contentoldContent = oldConfigFile.readlines()oldConfigFile.close()newfile = open(gmondFile,"w")row = 0flag = 0for line in oldContent: #print line row = row + 1 if cmp(line.strip().lstrip().rstrip(),'mcast_join = 239.2.11.71')==0: flag = flag + 1 line = args[1] + "\\n" log.write(time.strftime('%Y-%m-%d : %H-%M',time.localtime(time.time())) + "\\n") log.write('At %d row replace success'%row) if flag > 1: # Delete redundant line line = '' newfile.writelines(line)newfile.close() #setting gmond successlog.writelines("---------------------Execute gmond.exe");os.system("gmond")log.writelines("---------------------gmond is running");log.close()print 'setting ok'#该片段来自于http://byrx.net
相关内容
- python中的日期和时间格式化输出,python日期,下面是格式
- python返回昨天的日期,python返回昨天, #-*-coding:
- 关键字文本过滤器,关键字过滤器,大小写不敏感,可以
- python中id()函数的实用研究实例,python实例,>>>
- django 简单显示数据库的内容,django数据库内容,index.h
- python的循环语句while用法范例,pythonwhile,#!/usr/bin/p
- python将字符串转换为datetime类型,pythondatetime,python将字
- python 字符串模板功能,python字符串模板,# method 1te
- 处理各种编码的字符串,处理编码字符串,# file: Unic
- python dict初始化方式,pythondict初始化,python字典dict
评论关闭