title: Why doesn't Python recognize my utf-8 encoded source file?
body: <p>Here is a little tmp.py with a non ASCII character:</p>
  
  <pre><code>if __name__ == "__main__":
      s = 'ß'
      print(s)
  </code></pre>
  
  <p>Running it I get the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File ".\tmp.py", line 3, in &lt;module&gt;
      print(s)
    File "C:\Python32\lib\encodings\cp866.py", line 19, in encode
      return codecs.charmap_encode(input,self.errors,encoding_map)[0]
  UnicodeEncodeError: 'charmap' codec can't encode character '\xdf' in position 0: character maps to &lt;undefined&gt;
  </code></pre>
  
  <p>The Python docs <a href="http://docs.python.org/3.2/tutorial/interpreter.html#source-code-encoding" rel="noreferrer">says</a>:</p>
  
  <blockquote>
    <p>By default, Python source files are treated as encoded in UTF-8...</p>
  </blockquote>
  
  <p>My way of checking the encoding is to use Firefox (maybe someone would suggest something more obvious). I open tmp.py in Firefox and if I select View->Character Encoding->Unicode (UTF-8) it looks ok, that is the way it looks above in this question (wth ß
   symbol).</p>
  
  <p>If I put:</p>
  
  <pre><code># -*- encoding: utf-8 -*-
  </code></pre>
  
  <p>as the first string in tmp.py it does not change anything—the error persists.</p>
  
  <p>Could someone help me to figure out what am I doing  wrong?</p>