Here is a little tmp.py with a non ASCII character:
if __name__ == "__main__":
s = 'ß'
print(s)
Running it I get the following error:
Traceback (most recent call last):
File ".\tmp.py", line 3, in <module>
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 <undefined>
The Python docs says:
By default, Python source files are treated as encoded in UTF-8...
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).
If I put:
# -*- encoding: utf-8 -*-
as the first string in tmp.py it does not change anything—the error persists.
Could someone help me to figure out what am I doing wrong?