mehdi nora
mehdi nora

Reputation: 21

Not knowing a whole unicode character python

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 ?

Upvotes: 0

Views: 245

Answers (1)

JosefZ
JosefZ

Reputation: 30113

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 -> در ابل

Upvotes: 1

Related Questions