I'm trying to work with Urdu text but am unable to get the right output.
name = '\xd9\x87\xd9\x84\xd9\x84\xd8\xa7 \xd8\xa7\xd9\x85\xd8\xa7\xd9\x86'
print name
OUTPUT
هللا امان
DESIRED OUTPUT
امان اللہ
please advise.
I'm trying to work with Urdu text but am unable to get the right output.
name = '\xd9\x87\xd9\x84\xd9\x84\xd8\xa7 \xd8\xa7\xd9\x85\xd8\xa7\xd9\x86'
print name
OUTPUT
هللا امان
DESIRED OUTPUT
امان اللہ
please advise.
I see two main issues with your snippet.
The first is that in Arabic, there are special code points for entire words, and the word you are trying to print اللہ is called ARABIC LIGATURE ALLAH ISOLATED FORM
, which is 0xFDF2
or 0xEF 0xB7 0xB2
.
If you write it isolated (each individual character), you will not get the correct representation.
Second, your font in your terminal (or whatever application is being used to render the text) should support the glyph, and you should ensure that the text direction is switched to right-to-left.
Here is an example from the online Python shell:
>>> print(u"\uFDF2")
ﷲ
Since this shell is not configured for right to left you can see that it is printing it left to right.