且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Python将Unicode-Hex utf-8字符串转换为Unicode字符串

更新时间:2023-09-11 22:32:22

在您解码原始字符串的任何地方,它都可能是使用latin-1或近亲进行解码的.由于latin-1是Unicode的前256个代码点,因此可以:

Where ever you decoded the original string, it was likely decoded with latin-1 or a close relative. Since latin-1 is the first 256 codepoints of Unicode, this works:

>>> s = u'Gaga\xe2\x80\x99s'
>>> s.encode('latin-1').decode('utf8')
u'Gaga\u2019s'