在书写行之间创建空间
我目前正在创建一个函数,该函数从其他函数读取数据并将其写入桌面上的文本文件。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要附加换行符。
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')
使用 writelines 代替 write,它会打印序列中的所有内容都单独保存到文件中。添加空白字符串以添加双倍间距
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