如何在python中使用像\ u00e7这样的unicodes解码文本?

sma*_*org 4 python unicode utf-8 character-encoding python-2.7

嗨,我通过图书馆收到文本,当我打印收到的文本时,我看到一些非英文字符为“\u00e7”,而必须是“ç”。我想不知何故我需要对文本进行编码和重新解码,但我对 python 很陌生,如果这是正确的方法,我不会。你能指教我的方法吗?

fal*_*tru 5

使用unicode_escapeencoding解码字符串:

>>> s = r'\u00e7'
>>> print s
\u00e7
>>> print s.decode('unicode-escape')
ç
>>> 
Run Code Online (Sandbox Code Playgroud)

如果sys.stdout.encodingascii,打印将提高UnicodeEncodeError;在这种情况下,请对其进行显式编码:

>>> print s.decode('unicode-escape').encode('utf-8')
ç
Run Code Online (Sandbox Code Playgroud)