Search code examples
pythonpython-3.xnlpdata-cleaningarabic

Python prints Arabic text that includes punctuation incorrectly although it seems to be correctly stored


There is strange behavior on printing Arabic text that includes punctuation in Python.

Example:

word_1 = "...واحد"
word_2 = "اثنان"
word_list = [word_1, word_2]
print(word_list)

The output of the previous code is ['...واحد', 'اثنان'] but the correct output should be ['واحد...', 'اثنان']. This problem seems to exist only when I print the output. However, when I retrieve the first index I see the correct form. So the output of word_list[0] is ...واحد which is correct.

The problem is that I want to print something to the user at the end so I want to print the output correctly. Therefore, I want the output to be ['واحد...', 'اثنان'].

I would appreciate any help. Thank you in advance.


Solution

  • It's just because python is printing Left-to-Right If you copy your output and paste in a Right-to-Left environment you will see this is right (For example paste in Notepad and press Right-CTRL+Right-Shift to change notepad to Right to Left and you will see your output is without problem) This is your IDE issue that is printing Arabic output Left-to-Right

    Edit: You are writing into excel and should change paragraph-direction to RTL with this code

    workbook.add_format({'reading_order': 2})
    

    you can set reading_order to 2 to change paragraph direction from LTR to RTL