>>> s='未作評級'
>>> s
'\xe6\x9c\xaa\xe4\xbd\x9c\xe8\xa9\x95\xe7\xb4\x9a'
>>> s = unicode(s)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 0: ordinal not in range(128)
如何将 未作评级
放入 uniciode 中?
最佳答案
要么从一开始就使用 Unicode 字符串:
>>> s = u'未作評級'
或解码当前编码(似乎是UTF-8)的字符串。然后你得到一个 Unicode 字符串。
>>> s = '未作評級'.decode("utf-8")
关于python - utf-8 中的汉字字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17867297/