python_修改配置文件参数

#!/usr/bin/python
#coding:utf8

import os,re,csv

def readcsv(f):
    flist = []
    with open(f,'rU') as d:
    reader = csv.reader(d)
    for row in reader:
	flist.append(row[0])
    return ','.join(flist[1:])

def replace(l):
    fp1 = open('UserTest_Rules.ini','r')
    fp2 = open('text.ini','w')
    data1 = fp1.read()
    p = re.compile('(Element1_value)=(.+)')
    flist = '%s'% l
    data2 = p.sub(r'\1=%s'%flist,data1)
    fp2.write(data2)
    fp1.close()
    fp2.close()
    os.remove('UserTest_Rules.ini')
    os.rename('text.ini','UserTest_Rules.ini')

if __name__ == '__main__':
    files = '离职员工.csv'
    eplace(readcsv(files))


你可能感兴趣的:(python)