Revision 0079dbf3-c4a1-4105-8bb2-884b31f14eb8 - Stack Overflow

I write a python file in windows7 by sublime text, there are some Chinese character in the file, so when I run it, the character become some unrecognizable code(the same in cmd and git bash):

 # -*- coding: utf-8 -*- 
 str = "测试"
 
 print str
 
 arr = []
 arr.append(str)
 
 print arr

the result is:

 娴嬭瘯
 ['\xe6\xb5\x8b\xe8\xaf\x95']

How can I solve this problem? And what cause this problem?and the `arr` print result shouldn't be unicode like `\uXXX`?

BTW, without the `# -*- coding: utf-8 -*-` I can't even run it:

 $ python test.py
 File "test.py", line 2
 SyntaxError: Non-ASCII character '\xe6' in file test.py on line 2, but no encodi
 ng declared; see http://www.python.org/peps/pep-0263.html for details

I just google the statement, why can't run without it?


AltStyle によって変換されたページ (->オリジナル) /