如何在PYTHON中正确打印阿拉伯文字 [英] how to print Arabic text correctly in PYTHON
本文介绍了如何在PYTHON中正确打印阿拉伯文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Python 2.7,并且尝试打印此类阿拉伯字符串
I am using Python 2.7 and i try to print Arabic strings like these
print "ذهب الطالب الى المدرسة"
给出以下输出:
ط°ظ‡ط¨ ط§ظ„ط·ط§ظ„ط¨ ط§ظ„ظ‰ ط§ظ„ظ…ط¯ط±ط³ط©
目的是正确打印文本,而不是如何打印每一行.因此,如何正确以原始格式正确打印文本文件的字符串或内容?像:
The purpose is to print the text correctly, and not how to print each line. So, how can I print the string or content of text file correctly in its original form? like:
ذهب الطالب الى المدرسة
推荐答案
通过此模块,您可以纠正文本形状的方向. 只需安装点并使用它即可.
by this module you can correct your text shape an direction. just install pips and use it.
# install: pip install --upgrade arabic-reshaper
import arabic_reshaper
# install: pip install python-bidi
from bidi.algorithm import get_display
text = "ذهب الطالب الى المدرسة"
reshaped_text = arabic_reshaper.reshape(text) # correct its shape
bidi_text = get_display(reshaped_text) # correct its direction
这篇关于如何在PYTHON中正确打印阿拉伯文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文