Confusion about python unicode
I have writen a python file in windows7 by sublime text, there are some Chinese characters in the file, so when I run it, the characters become unrecognizable (the same occurs 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? what is the cause of this problem? and the arr print result shouldn't be unicode like \uXXX?
By the way, 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 googled the statement, why can't the code run without it?
hh54188
- 15.7k
- 35
- 117
- 194
lang-py