python3 把str的unicode轉中文
>>> print('\u722c\u866b')
>>> 爬蟲
>>> print('uni722c'.replace("uni", r"\u"))
>>> \u722c
- 3、python3以上取消了字符串的decode方法,所以你如果直接用str.decode(“utf-8”)的字符串轉爲unicode,會報如下錯誤AttributeError: ‘str’ object has no attribute ‘decode’
>>> print('uni722c'.replace("uni", r"\u").decode('unicode_escape'))
Traceback (most recent call last):
File "<input>", line 1, in <module>
AttributeError: 'str' object has no attribute 'decode'
>>> print('uni722c'.replace("uni", r"\u").encode('utf-8').decode('unicode_escape'))
>>> 爬