用 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' + '\n' 8 lines[2]='interface = mon-33c4960d-0c' + '\n' 9 10 with open(filename,'w') as f: 11 for data in lines: 12 f.write(data) 13 f.flush()