将 bidi 用于双向 a model.txt

use bidi for bidirection a model.txt

我想在我的代码中使用 model.txt 行,但行中的所有单词都是波斯语(从右到左)。我使用此代码来更正它们,但它给我错误。 我知道如何解决错误,但如果我将线条更改为字符串,我将无法纠正它们的形状 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)

已解决! 我为我的文件使用了编码,它是固定的! 感谢我的朋友 armin 告诉我我的错误。

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)