Home > Enterprise >  How to read txt files with those languages which is read from right to left with python
How to read txt files with those languages which is read from right to left with python

Time:03-26

Here is a code that is reading a file for me. But each word of the file is reversed from the original text that I have put in line.txt file.

line.txt

  اور ایک 

test.py

import re

f = open("line.txt",encoding="utf-8")
text = f.read()
print(text)

OUTPUT enter image description here

CodePudding user response:

try this https://github.com/mpcabd/python-arabic-reshaper

or print(text[::-1])

CodePudding user response:

The simple solution is to print the reversed text:

print(text[::-1])

Another solution is to use a bi-directional library python-bidi

from bidi.algorithm import get_display

f = open("line.txt",encoding="utf-8")
text = f.read()
print(get_display(text))
  • Related