我试过了print a_str.decode("utf-8")
,,,,..print uni_str
print uni_str.decode("utf-8")
print uni_str.encode("utf-8")
但只有第一个有效。
>>> print '\xe8\xb7\xb3'.decode("utf-8")
跳
>>> print u'\xe8\xb7\xb3\xe8'
è·³è
>>> print u'\xe8\xb7\xb3\xe8'.decode("utf-8")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)
>>> print u'\xe8\xb7\xb3\xe8'.encode("utf-8")
è·³è
我真的很困惑如何正常显示 Unicode 字符串。如果我有这样的字符串:
a=u'\xe8\xb7\xb3\xe8'
,我该如何打印a
?