简体   繁体   中英

Printing urdu (non-latin language) word by word using python

I am trying to print Urdu words using python. I read about Unicode but the [problem I face is that python tries to print the Urdu just like English, that is, from left to right and character by character. In Urdu characters] cannot be printed like those in English. I have already tried few solutions like the one mentioned here but they didn't work for me. I have been trying to print my Urdu string with the following code.

text_string = "آکاش کمار".decode('utf-8')   
print text_string

the output I get on Ubuntu terminal is like English from left to right instead of right to left and that too character by character.

I believe the problem is with Gnome Terminal which does not support bidirectional (ie, right-to-left or "RTL") text output. If I run your above program (with an encoding declaration):

# -*- coding: utf-8 -*-
text_string = "آکاش کمار".decode('utf-8')
print(text_string)

in an Emacs shell buffer (with does support mixed LTR and RTL output), I get the correct output:

$ python2 urdu.py
آکاش کمار
$ 

However, if I run it in a Gnome Terminal, I get the backwards output that you posted.

If you don't use Emacs, another alternative is to install the mlterm (multilingual terminal) package and use the terminal emulator it provides.

通过使用 LibRaqm,您的问题可以解决,下面给出了该库的链接https://github.com/HOST-Oman/libraqm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM