I have a variable in which Unicode characters are typed with string
print(x)
# output -> '\u062f\u0631 \u0627\u0628\u0644'
print(type(x))
# output -> <class 'str'>
how can i convert x in utf8 ?
CodePudding user response:
Use .encode('raw_unicode_escape').decode('unicode_escape')
for doubled Reverse Solidi, see Python Specific Encodings
x= '\\u062f\\u0631 \\u0627\\u0628\\u0644'
print(x, '->', x.encode('raw_unicode_escape').decode('unicode_escape'))
\u062f\u0631 \u0627\u0628\u0644 -> در ابل