• <i id='RS7GV'><tr id='RS7GV'><dt id='RS7GV'><q id='RS7GV'><span id='RS7GV'><b id='RS7GV'><form id='RS7GV'><ins id='RS7GV'></ins><ul id='RS7GV'></ul><sub id='RS7GV'></sub></form><legend id='RS7GV'></legend><bdo id='RS7GV'><pre id='RS7GV'><center id='RS7GV'></center></pre></bdo></b><th id='RS7GV'></th></span></q></dt></tr></i><div id='RS7GV'><tfoot id='RS7GV'></tfoot><dl id='RS7GV'><fieldset id='RS7GV'></fieldset></dl></div>
  • <legend id='RS7GV'><style id='RS7GV'><dir id='RS7GV'><q id='RS7GV'></q></dir></style></legend>
      <bdo id='RS7GV'></bdo><ul id='RS7GV'></ul>
      <tfoot id='RS7GV'></tfoot>

      1. <small id='RS7GV'></small><noframes id='RS7GV'>

        将 for 循环的输出保存到文件

        Saving output of a for-loop to file(将 for 循环的输出保存到文件)
      2. <small id='nhBd8'></small><noframes id='nhBd8'>

              <bdo id='nhBd8'></bdo><ul id='nhBd8'></ul>

                  <tbody id='nhBd8'></tbody>

                  <tfoot id='nhBd8'></tfoot>

                  <i id='nhBd8'><tr id='nhBd8'><dt id='nhBd8'><q id='nhBd8'><span id='nhBd8'><b id='nhBd8'><form id='nhBd8'><ins id='nhBd8'></ins><ul id='nhBd8'></ul><sub id='nhBd8'></sub></form><legend id='nhBd8'></legend><bdo id='nhBd8'><pre id='nhBd8'><center id='nhBd8'></center></pre></bdo></b><th id='nhBd8'></th></span></q></dt></tr></i><div id='nhBd8'><tfoot id='nhBd8'></tfoot><dl id='nhBd8'><fieldset id='nhBd8'></fieldset></dl></div>
                • <legend id='nhBd8'><style id='nhBd8'><dir id='nhBd8'><q id='nhBd8'></q></dir></style></legend>
                • 本文介绍了将 for 循环的输出保存到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我打开了一个包含爆炸结果的文件,并将结果以 fasta 格式打印到屏幕上.

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

                  代码如下所示:

                  result_handle = open("/Users/jonbra/Desktop/my_blast.xml")
                  
                  from Bio.Blast import NCBIXML
                  blast_records = NCBIXML.parse(result_handle)
                  blast_record = blast_records.next()
                  for alignment in blast_record.alignments:
                      for hsp in alignment.hsps:
                          print '>', alignment.title
                          print hsp.sbjct
                  

                  这会将 fasta 文件列表输出到屏幕上.但是如何创建文件并将 fasta 输出保存到该文件中?

                  This outputs a list of fasta files to the screen. But how can I create a file and save the fasta output to this file?

                  更新:我想我必须用 something.write() 替换循环中的打印语句,但是我们编写的 '>'、alignment.title 将如何?

                  Update: I guess I would have to replace the print statements within the loop with something.write(), but how will the '>', alignment.title we written?

                  推荐答案

                  首先,创建一个文件对象:

                  First, create a file object:

                  f = open("myfile.txt", "w") # Use "a" instead of "w" to append to file
                  

                  您可以打印到文件对象:

                  You can print to a file object:

                  print >> f, '>', alignment.title
                  print >> f, hsp.sbjct 
                  

                  或者你可以写信给它:

                  f.write('> %s
                  ' % (alignment.title,))
                  f.write('%s
                  ' % (hsp.sbjct,))
                  

                  然后你就可以关闭它了:

                  You can then close it to be nice:

                  f.close()
                  

                  这篇关于将 for 循环的输出保存到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                  Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                  Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                  Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                  Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                  Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)

                        <tbody id='a8EpD'></tbody>
                      <tfoot id='a8EpD'></tfoot><legend id='a8EpD'><style id='a8EpD'><dir id='a8EpD'><q id='a8EpD'></q></dir></style></legend>
                    • <small id='a8EpD'></small><noframes id='a8EpD'>

                          <bdo id='a8EpD'></bdo><ul id='a8EpD'></ul>

                          <i id='a8EpD'><tr id='a8EpD'><dt id='a8EpD'><q id='a8EpD'><span id='a8EpD'><b id='a8EpD'><form id='a8EpD'><ins id='a8EpD'></ins><ul id='a8EpD'></ul><sub id='a8EpD'></sub></form><legend id='a8EpD'></legend><bdo id='a8EpD'><pre id='a8EpD'><center id='a8EpD'></center></pre></bdo></b><th id='a8EpD'></th></span></q></dt></tr></i><div id='a8EpD'><tfoot id='a8EpD'></tfoot><dl id='a8EpD'><fieldset id='a8EpD'></fieldset></dl></div>