Skip to content Skip to sidebar Skip to footer

Python - Decode Unicode String

I have a unicode string like this mm = u'A\xe2\x80\x8ct\xe2\x80\x8ch\xe2\x80\x8c\xe2\x80\x8c\xe2\x80\x8c\xe2\x80\x8c\xe2\x80\x8c\xe2\x80\x8cl\xe2\x80\x8c\xe2\x80\x8c\xe2\x80\x8ce\x

Solution 1:

You need to undo the incorrect encoding first.

>>> u'A\xe2\x80\x8ct\xe2\x80\x8ch...\xe2\x80\x8cdes'.encode('latin-1').decode('utf-8')
u'A\u200ct\u200ch\u200c\u200c\u200c\u200c\u200c\u200cl\u200c\u200c\u200ce\u200c\u200c\u200c\u200ct\u200c\u200c\u200c\u200c\u200c\u200c\u200ci\u200c\u200c\u200c\u200c\u200cc\u200c\u200c\u200c\u200c\u200c\u200c\u200c\u200c\u200c\u200c Bilbao (n)\tC\u200cD\u200c \u200c\u200c\u200c\u200c\u200c\u200cM\u200c\u200c\u200ci\u200c\u200c\u200c\u200cr\u200c\u200c\u200c\u200c\u200c\u200c\u200ca\u200c\u200c\u200c\u200c\u200cn\u200c\u200c\u200c\u200c\u200c\u200c\u200c\u200c\u200c\u200cdes'
>>> print u'A\xe2\x80\x8ct\xe2\x80\x8ch...\xe2\x80\x8cdes'.encode('latin-1').decode('utf-8')
A‌t‌h‌‌‌‌‌‌l‌‌‌e‌‌‌‌t‌‌‌‌‌‌‌i‌‌‌‌‌c‌‌‌‌‌‌‌‌‌‌ Bilbao (n)    C‌D‌ ‌‌‌‌‌‌M‌‌‌i‌‌‌‌r‌‌‌‌‌‌‌a‌‌‌‌‌n‌‌‌‌‌‌‌‌‌‌des

Post a Comment for "Python - Decode Unicode String"