?python對于Unicode編碼可以使用decode進(jìn)行轉(zhuǎn)換成中文:
>>> str = b'\xe8\xb4\xb9\xe8\x84\x91\xe5\xad\x90'
>>> str.decode('utf-8')
'費腦子'
如果是字符串類型的Unicode編碼沒辦法直接用decode進(jìn)行轉(zhuǎn)換:
>>>?str ="\\xe8\\xb4\\xb9\\xe8\\x84\\x91\\xe5\\xad\\x90"
>>>?str.decode('utf-8')
Traceback (most recent call last):
? File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'decode'
處理方式:
>>>?str = eval("b" + "\"" + str + "\"")
>>>?str.decode('utf-8')
'費腦子'