使用 arabic-reshaperin 和 bidi 转换 py 中的文本(从文件转换)
use arabic-reshaperin and bidi for convert a text in py (convert from file)
我需要在 python 中使用 reshaperin 和 bidi 来转换一些阿拉伯语文本
我的问题是如何使用 arabic-reshaper 转换 txt 文件中的文本并将转换后的文本保存在其他 txt 文件中
这是我转换一行的代码
import arabic_reshaper
from bidi.algorithm import get_display
text = 'سلام محمد خوبی'
test = arabic_reshaper.reshape(text)
print(get_display(test))
我知道这是一个简单的问题,但直到今天我才开始使用 Python
发送
可以使用列表
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')
我需要在 python 中使用 reshaperin 和 bidi 来转换一些阿拉伯语文本
我的问题是如何使用 arabic-reshaper 转换 txt 文件中的文本并将转换后的文本保存在其他 txt 文件中
这是我转换一行的代码
import arabic_reshaper
from bidi.algorithm import get_display
text = 'سلام محمد خوبی'
test = arabic_reshaper.reshape(text)
print(get_display(test))
我知道这是一个简单的问题,但直到今天我才开始使用 Python 发送
可以使用列表
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')