Saving output of a for-loop to file

前端 未结 5 963
礼貌的吻别
礼貌的吻别 2020-12-17 06:32

I have opened a file with blast results and printed out the hits in fasta format to the screen.

The code looks like this:

result_handle = open(\"/Use         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-17 06:50

    There are two general approaches. Outside of python:

    python your_program.py >output_file.txt
    

    Or, inside of Python:

    out = open("output_file.txt", "w")
    for alignment in blast_record.alignments:
        for hsp in alignment.hsps:
            print >>out, '>', alignment.title
            print >>out, hsp.sbjct
    out.close()
    

提交回复
热议问题