我需要在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
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')