开发者

Creating space in between written lines

开发者 https://www.devze.com 2023-02-28 16:39 出处:网络
I\'m currently creating a function that reads in data from other functions and writing it out to a text file on my desktop.

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开发者_StackOverflow中文版 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?


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

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


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]);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号