用 python 修改文件中指定的行数

 1 #! /bin/python
 2 
 3 filename='setup.ini'
 4 lines=[]
 5 with open(filename,'r') as f:
 6     lines=f.readlines()
 7 lines[1]='namespace = qmone-33c49600-4c22-486d-a397-e4f02bcdcf18' + '
'
 8 lines[2]='interface = mon-33c4960d-0c' + '
'
 9 
10 with open(filename,'w') as f:
11     for data in lines:
12         f.write(data)
13     f.flush()
原文地址:https://www.cnblogs.com/wangjq19920210/p/10143575.html