s = u'Gaga\xe2\x80\x99s',但需要转换为t = u'Gaga\u2019s'
如何最好地做到这一点?

最佳答案

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

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

10-06 01:45