title: Saving output of a for-loop to file
body: <p>I have opened a file with blast results and printed out the hits in fasta format to the screen.</p>
  
  <p>The code looks like this:</p>
  
  <pre><code>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 '&gt;', alignment.title
          print hsp.sbjct
  </code></pre>
  
  <p>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?</p>
  
  <p>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?</p>