4

One of my string variables contains unicode code \u0631\u064e\u062c\u0627. I want to convert it to a string and see what characters were encoded by it.

Is it possible and how can I do it in python?

3 Answers 3

3

That's just an internal representation. If you print it, you will get what you want:

>>> print("\u0631\u064e\u062c\u0627")
رَجا

In short, this is how Python stores the characters رَ and جا. If you tell Python to print them, you'll see them converted back to their human-readable form.

Sign up to request clarification or add additional context in comments.

Comments

3

Decode using unicode_escape encoding:

In Python 2.x:

>>> text = r'\u0631\u064e\u062c\u0627'
>>> print(text)
\u0631\u064e\u062c\u0627
>>> print(text.decode('unicode-escape'))
رَجا

In Python 3.x:

>>> text = r'\u0631\u064e\u062c\u0627'
>>> print(text.encode().decode('unicode-escape'))
رَجا

Comments

1
>>> print u"\u0631\u064e\u062c\u0627"
رَجا

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.