[Python-ideas] Fwd: Add Unicode-aware str.reverse() function?

Jonathan Fine jfine2358 at gmail.com
Sat Sep 8 16:08:48 EDT 2018


Chris Angelico wrote:

> Generally, problems with RTL text are *display* problems, and are not
> solved by reversing strings.

I very much agree with this statement, with one exception. If you wish
to display RTL text on a LTR display, then a suitable reversing of
strings is probably part of the solution.

Using Google translate and a Python console I get

    English: integer
    Arabic: عدد صحيح   # Copy and paste from Google translate into gmail
    Python: عدد صحيح

The Python output shown here is obtained by

    1. Copy and paste from Google translate into Python console.
    2. And copied back again into gmail

Notice how it looks just the same as the direct translation.

So what's the problem? In the Python console, it doesn't look right.
Here's what you should get.

    >>> 'عدد صحيح'
    '\xd8\xb9\xd8\xaf\xd8\xaf \xd8\xb5\xd8\xad\xd9\x8a\xd8\xad'

See, the arabic is exactly the same. But when I paste the arabic
string into the Python console, I get something that looks quite
different, and sort of backwards.

The problem, I think, is that the Python console is outputting the
arabic glyphs from left to right. By the way, I get the same problem
in the bash shell.

-- 
Jonathan


More information about the Python-ideas mailing list