如何让我的循环在每个输出开始一个新行?

How can I make my loop start a new line every output?

这就是我目前所知道的。问题出在我写入文件的底部。数据基本上是我从中提取值的一堆数组,我想将每个数组写入一行,跳过一行,然后写入下一个数组。我尝试在 %s 之后添加 \n 但它最终将所有内容写入垂直列中的文件。

for i in frange(2.0, 7.5, 0.5):
    filename = str('pH')+str(i)+str('_calcpka.dat')
    readFile(array_pf, filename)      ##goes through files and takes data I need


df = []
for i in array_pf:          ##does some math and puts into new array..
    x = 1-i
    df.append(x)


titration_curves = open('titration_curves.dat', 'w')   ##writes to file
for i in df:
    titration_curves.write("%s " % i)

看起来 df 只是一个值数组,而不是数组的数组。您需要做的是将您的输入放入一个数组数组中,其中每个内部数组对应于文件中的一行。然后你做这样的事情:

for df in dfs:
    for i in df:
        titration_curves.write("%s " % i)
    titration_curves.write("\n")