增加行间距

1 投票
2 回答
7543 浏览
提问于 2025-04-16 16:27

我现在正在写一个函数,这个函数可以从其他函数那里读取数据,然后把这些数据写到我桌面上的一个文本文件里。

def outputResults(filename):
"""This function serves to output and write the results from analyzeGenome.py to a text file \
   Input: filename of output file, dictionary of codon frequencies, dictionary of codon counts \
        GC-content, FASTA header, & sequence length

   Output: Text file containing all the above """

outString = "Header = %s" %header
filename.write(outString)

outString2 = "Sequence Length = %.3F MB" % length
filename.write(outString2)

当我这样做的时候,Python会把每一行数据一个接一个地写在文本文件里。我想知道怎么才能让它在下一行打印,并且在行与行之间加一个空行呢?

2 个回答

2

与其使用写入文件的方式,不如用 writelines,这个方法会把序列中的每一项都单独打印到文件的一行上。如果想要增加行间距,可以在序列中添加一个空字符串。

  filename.writelines([outString, "", outString2]);
5

你需要添加一个换行符。

http://docs.python.org/library/stringio.html

output.write('第一行。\n')

撰写回答