Python 在书写行之间创建空格

Python 在书写行之间创建空格,python,file-io,io,Python,File Io,Io,我目前正在创建一个函数,从其他函数中读取数据并将其写入桌面上的文本文件 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 co

我目前正在创建一个函数,从其他函数中读取数据并将其写入桌面上的文本文件

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会在文本文件中一行接一行地打印这些行。如何打印到下一行并在行与行之间添加空格?

使用write,而不是write,它将序列中的所有内容打印到自己行上的文件中。添加空白字符串以添加双间距

  filename.writelines([outString, "", outString2]);
使用,而不是写,它将序列中的所有内容打印到自己行上的文件中。添加空白字符串以添加双间距

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

您需要附加换行符。


output.write('First line.\n')
您需要附加换行符。


output.write('First line.\n')

@Francis该
\n
位于字符串中需要换行符的位置。在我看来,它就在
%s
@Francis之后,
\n
就在字符串中需要换行符的地方。在我看来,它就在
%s