问题
The very simple example is:
city = "المكلا"
print(city)
I am expecting the output to be:
المكلا
But in fact the ouput is the reverse string (the letters look a little different because they have a start-, middle- and end-form). I can't paste it here, because copy-pasting corrects the order of the string again.
How can I print Arabic correctly to the Linux terminal? The surounding text is left-to-right (LTR) and only this line needs to be right-to-left (RTL). Is there a UFT-8 character that can tell ther terminal that?
回答1:
To create a string with the RTL character:
rtl = u'\u200f'
Python 3 uses UTF strings by default, so in that case the "u" in front of the string would be unnecessary.
If the problem is actually that the terminal just can't render correctly, you could manually reverse the string.
test = 'Hello world'
test = test[::-1]
# test == 'dlroW olleH'
There is also the python-bidi library which might be able to help. (source)
来源:https://stackoverflow.com/questions/33700735/print-arabic-or-any-right-to-left-writing-system-string-to-linux-terminal-using