title: Can write to stdout using latin-1 encoding but not to a file (Python 2.6)
body: <p>I have data which is unicode and wish to write it to a file. I am using python 2.6. I am able to print the encoded values but am not able to write it to a file. The default encoding for the environment is UTF-8. Tried using codecs as well, but no luck there too.  Here is a sample code snippet that I am using. </p>
  
  <pre><code>#!/usr/bin/python
  import sys
  import codecs
  import csv
  
  sh = [u'T\xe9l\xe9vista S.A.', u'T\xe9l\xe9vista S.A.', 'Python']
  print sys.stdout.encoding
  f = codecs.open('listwrite.txt', 'w', encoding='latin-1')
  for item in sh:
    f.write(item)
  f.close()
  
  for i in sh:
    print i.encode('latin-1')
  </code></pre>
  
  #
  
  <p>Output:</p>
  
  <pre><code>UTF-8
  Télévista S.A.
  Télévista S.A.
  Python
  
  Contents of listwrite.txt
  TÃ©lÃ©vista S.A.TÃ©lÃ©vista S.A.Python
  </code></pre>
  
  #
  
  <p>As seen above the file is being written in UTF-8 encoding and not Latin-1. How do I change it and override the default encoding for the file. </p>
  
  <p><strong>Edit: 2</strong></p>
  
  <p>Also, writing using a csv writer gives UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 1: ordinal not in range(128)</p>
  
  <p>Code below: </p>
  
  <pre><code>#!/usr/bin/python
  import sys
  import codecs
  import csv
  
  sh = [u'T\xe9l\xe9vista S.A.', u'T\xe9l\xe9vista S.A.', 'Python']
  print sys.stdout.encoding
  c = csv.writer(codecs.open('listwrite.txt', 'w', encoding='latin-1'), quoting=csv.QUOTE_NONE)
  c.writerow(sh)
  f.close()
  
  for i in sh:
    print i.encode('latin-1')
  </code></pre>