Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

edited tags
Link
Codie CodeMonkey
  • 8.1k
  • 2
  • 31
  • 49
grammar and punctution for clarity
Source Link

Confuse Confusion about python unicode

I writehave writen a python file in windows7 by sublime text, there are some Chinese charactercharacters in the file, so when I run it, the charactercharacters become some unrecognizable code(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? And what is the cause of this problem?andproblem? and the arr print result shouldn't be unicode like \uXXX?

BTWBy 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 googlegoogled the statement, why can't the code run without it?

Confuse about python unicode

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?

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?

Source Link
hh54188
  • 15.7k
  • 35
  • 117
  • 194

Confuse about python unicode

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?

lang-py

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