0

i want to use lines of model.txt in my code but all of words in lines are persian(Right to Left).i use this code for correct them but its give me error. i know how i can solve error but if i change my lines to strings i cant correct their shape and direction.any help?

import arabic_reshaper

from bidi.algorithm import get_display


def readFile():
    with open('D:/visual stadio/python/captcha maker/test/model.txt','r') as file:
        lines= file.readlines()

    reshaped_text = arabic_reshaper.reshape(lines) 
       #if i use reshaped_text = arabic_reshaper.reshape(str(lines)) it will 
       #work fine but it will give me this answer: ['سلام\n', 
       #'سلامس\n', 'آدامس\n', 'پنیر\n', 'چتر\n','پاوه'] this are my words in model.txt but not fixed.
    bidi_text = get_display(reshaped_text)         

    return bidi_text 
bidi_text=readFile()
print(bidi_text)
Jalal Razavi
  • 203
  • 3
  • 8

1 Answers1

0

solved! i use an encode for my file and it's fixed! thanks to my friend armin who told me my mistake.

import arabic_reshaper
import codecs
from bidi.algorithm import get_display


def readFile():
    with open('D:/visual stadio/python/captcha maker/test/model.txt','r',encoding='utf8') as file:
        lines= file.readlines()
        lista=[]

        for line in lines:
                reshaped_text = arabic_reshaper.reshape(line) 
                bidi_text = get_display(reshaped_text)         
                lista.append(bidi_text)
        return lista
lista=readFile()
print(lista)
Jalal Razavi
  • 203
  • 3
  • 8