How To Decode Unicode Raw Literals To Readable String?
If I assign unicode raw literals to a variable, I can read its value: >>> s = u'\u0421\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0442\u043f\u0440\u0430\u043
Solution 1:
Use the unicode_escape codec:
s.decode('unicode_escape')
Solution 2:
If you are getting weird results when decoding try following
print repr(s).decode('unicode-escape').encode('latin-1') // or encode using some other encoding
It could be that python terminal is using default ASCII and there is symbol that goes out of range.
Post a Comment for "How To Decode Unicode Raw Literals To Readable String?"