这里有一个小tmp.带有非ASCII字符的py:
if __name__ == "__main__":
s = 'ß'
print(s)
运行它时,会出现以下错误:
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>
Python docs says:
默认情况下,Python源文件被视为以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).
如果我说:
# -*- encoding: utf-8 -*-
作为tmp中的第一个字符串.py它不会改变任何错误持续存在的情况.
有人能帮我找出我做错了什么吗?