我是python的新手:
我正在尝试将文本文件写入其他格式。给定格式的文件:
[header]
rho = 1.1742817531
mu = 1.71997e-05
q = 411385.1046712013
...
我想要:
[header]
1.1742817531,1.71997e-05,411385.1046712013,...
并能够在其下写连续的行。
现在,我有以下内容:
inFile = open('test.txt','r')
f = open('test.txt').readlines()
firstLine = f.pop(0) #removes the first line
D = ''
for line in f:
D = line.strip('\n')
b=D.rfind('=')
c=D[b+2:]
line = inFile.readline()
它仅返回最后一个值“ 3”。
如何获取它以我想要的格式返回字符串(将保存到新的txt文件中)?
谢谢。