在书写行之间创建空间

发布于 2024-11-03 10:44:54 字数 591 浏览 5 评论 0原文

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

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

I'm currently creating a function that reads in data from other functions and writing it out to a text file on my desktop.

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)

When I do this, python prints the lines one after another in the text file. How can I print onto the next line and add a space in between the lines?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

菊凝晚露 2024-11-10 10:44:54

您需要附加换行符。
http://docs.python.org/library/stringio.html

输出.write('第一行。\n')

You need to append a linebreak.
http://docs.python.org/library/stringio.html

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

向日葵 2024-11-10 10:44:54

使用 writelines 代替 write,它会打印序列中的所有内容都单独保存到文件中。添加空白字符串以添加双倍间距

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

Instead of write, use writelines, which prints everything in the sequence out to a file on its own line. Add a blank string to add double spacing

  filename.writelines([outString, "", outString2]);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文