使用阿拉伯文变形和比迪用于转换py中的文本(从文件转换)

问题描述 投票:0回答:1

我需要在python中使用reshaperin和bidi来转换一些阿拉伯文本

我的问题是我如何使用阿拉伯整形器在txt文件内转换文本并将转换后的文本保存在其他txt文件中

我的代码用于转换一行

import arabic_reshaper
from bidi.algorithm import get_display
text = 'سلام محمد خوبی'

test = arabic_reshaper.reshape(text)
print(get_display(test))

我知道这是一个简单的问题,但是直到今天我还没有使用Pythontnx

python arabic
1个回答
0
投票
可以使用列表

import arabic_reshaper from bidi.algorithm import get_display text = 'سلام محمد خوبی' test = arabic_reshaper.reshape(text) print(get_display(test)) lines = [] with open("file.txt", encoding="utf8") as file_in: for line in file_in: lines.append(arabic_reshaper.reshape(line)) #Save it to file with a line break with open("file2.txt", "w", encoding="utf8") as output: #created if it doesnt exist for line in lines: output.write(str(line) + '\n')

© www.soinside.com 2019 - 2024. All rights reserved.