I have a string like so:
>>> t
\'\\\\u0048\\\\u0065\\\\u006c\\\\u006c\\\\u006f\\\\u0020\\\\u20ac\\\\u0020\\\\u00b0\'
That I made u
Not sure if this is appropriate for your situation, but you could try using unicode_escape
:
>>> t
'\\u0048\\u0065\\u006c\\u006c\\u006f\\u0020\\u20ac\\u0020\\u00b0'
>>> type(t)
>>> enc_t = t.encode('utf_8')
>>> enc_t
b'\\u0048\\u0065\\u006c\\u006c\\u006f\\u0020\\u20ac\\u0020\\u00b0'
>>> type(enc_t)
>>> dec_t = enc_t.decode('unicode_escape')
>>> type(dec_t)
>>> dec_t
'Hello € °'
Or in abbreviated form:
>>> t.encode('utf_8').decode('unicode_escape')
'Hello € °'
You take your string and encode it using UTF-8
, and then decode it using unicode_escape
.