right-to-left languages in Python
Asked Answered
B

2

14

I want to write a Hebrew string in Python and then show it onscreen. The problem is that I get a mirror view of what I wrote. How can I set the string to use RTL instead of left to right?

Bihari answered 4/10, 2010 at 14:54 Comment(4)
Do you use any GUI library to show it on screen? Or maybe you just print it to console?Mckinleymckinney
It's not pretty, but have you tried .reverse()? ;)Kendrickkendricks
There's more to proper Hebrew typesetting than just the display order! These ‘advanced text layout’ features are dealt with by GUI apps (eg using Uniscribe or Pango), but are pretty much out of reach for console apps.Martica
I can't use reverse(); I didn't find the function. The GUI I use is PsychoPy. Thank you for your helpBihari
E
14

Did you try this?

http://pypi.python.org/pypi/python-bidi/

http://pypi.python.org/pypi/django-bidi-utils

The Israeli FOSS community is doing a lot in this direction. Surprisingly, they happily collaborate also with Farsi speakers :-)

pyfribidi for windows or any other bidi algorithm

Enrollment answered 13/7, 2011 at 13:13 Comment(4)
it is Farsi not Pharsi!Arborvitae
No need to use ! It's like you are yelling ... Thanks for enlightening usEnrollment
Not surprising at all. They are a nice bunch!Commissionaire
@Arborvitae It's neither Pharsi, nor Farsi, In English it's called Persian. It's like you say Dutch instead of GermanCalorific
S
6

I know I'm pretty late to the party, but you can always use:

 " שלום hello "[::-1]

But the real solution is to use:

from bidi.algorithm import get_display
print(get_display("היי"))
Sidky answered 14/9, 2019 at 15:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.