Some Unicode data is stored in file as '\u84b8\u6c7d\u5730' without any encoding.
Is there a way to covert them back in Python?
Some Unicode data is stored in file as '\u84b8\u6c7d\u5730' without any encoding.
Is there a way to covert them back in Python?
>>> print '\u84b8\u6c7d\u5730'.decode('unicode-escape')
蒸汽地
This code helped me to decode the string in Python 3:
text = '\\u041d\\u0435\\u0442 \\u043f\\u0430\\u0440\\u0430\\u043c\\u0435\\u0442\\u0440\\u0430'
res = text.encode().decode('unicode_escape')
print(res)
encode()
- convert a str
to a bytes
objectdecode('unicode_escape')
- convert a bytes
object to a str
using codec unicode_escape
. See Python 3 Standard Encodings.