title: Why is python writing out in Chinese characters?
body: <p>This is my first question on Stack Overflow and so I want to apologise first if my question is not formatted correctly. I am not particularly experienced with coding, but am trying to solve a specific problem with my work.</p>
  
  <p>I am trying to replace the headers of a large fasta file (used for aligning DNA sequences). I have a txt file containing the fasta alignment (alignment.txt), which has contents like this:</p>
  
  <pre><code>&gt;418035201_b1_168_m12_gag__Assembly_8
  ATGGGTGCGAGAGCGTCAGTATTAAGTGGGGGAAA......
  
  &gt;418035201_b1_168_m12_gag__Assembly_19
  ATGGGTGCGAGAGCGTCAGTATTAAGTGGGGGAAA......
  </code></pre>
  
  <p>I also have a text file containing the desired names (newheaders.txt), which has contents like this:</p>
  
  <pre><code>&gt;418035201_pM_s38_B168_m12_gag_c08_M13F_X00_consensus
  &gt;418035201_pM_s38_B168_m12_gag_c19_M13F_X00_consensus
  ....
  </code></pre>
  
  <p>I am trying to replace the headers (lines beginning '>') in the alignment.txt file with the new headers in the newheaders.txt file.</p>
  
  <p>I have a python script with the following contents:</p>
  
  <pre><code>#!/usr/bin/env python
  
  
  fasta= open('alignment.txt','r')
  newnames= open('newheaders.txt','r')
  newfasta= open('newfasta.txt', 'w')
  
  for line in fasta:
      if line.startswith('&gt;'):
          newname= newnames.readline()
          newfasta.write(newname)
      else:
          newfasta.write(line)
          print line
  
  fasta.close()
  newnames.close()
  newfasta.close()
  </code></pre>
  
  <p>When I run this, I get the following output:</p>
  
  <pre><code>&gt;418035201_pM_s38_B168_m12_gag_c08_M13F_X00_consensus
  䄊䝔䝇䝔䝃䝁䝁䝃䍔䝁䅔呔䅁呇䝇䝇䅇䅁呁䅔䅇䝔䅃䝔䝇䅁䅁䅁呔....
  
  &gt;418035201_pM_s38_B168_m12_gag_c19_M13F_X00_consensus
  䄊䝔䝇䝔䝃䝁䝁䝃䍔䝁䅔呔䅁呇䝇䝇䅇䅁呁䅔䅇䝔䅃䝔䝇䝁䅁䅁呔....
  </code></pre>
  
  <p>'line' is being changed from Roman characters to Chinese characters. It should NOT be in Chinese characters, and I can't work out for the life of me why this is happening!</p>
  
  <p>When 'line' is printed to the console, it prints it correctly. I.e.</p>
  
  <pre><code>ATGGGTGCGAGAGCGTCAGTATTAAGTGGGGGAAAATTAGATGCGTGGGAGAA....
  </code></pre>
  
  <p>So I believe it must be something to do with how it is writing out.</p>
  
  <p>If anybody would be able to help me with this or provide some insight I would greatly appreciate it, thank you.</p>
  
  <p>[Edit: Now resolved. See below. Thanks everyone!]</p>