如何读取.rtf文件并将其转换为python3字符串并可以存储在python3列表中?

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

我有一个.rtf文件,我想通过使用任何软件包使用python3读取文件并将字符串存储到列表中,但是它应该与Windows和Linux兼容。

我尝试了striprtf,但read_rtf无法正常工作。

from striprtf.striprtf import rtf_to_text
from striprtf.striprtf import read_rtf
rtf = read_rtf("file.rtf")
text = rtf_to_text(rtf)
print(text)

但是在此代码中,错误是:无法导入名称'read_rtf'

[任何人都可以建议任何方法从python3的.rtf文件中获取字符串吗?

python python-3.x rtf
1个回答
0
投票

您尝试过这个吗?

with open('yourfile.rtf', 'r') as file:
    text = file.read()
print(text)
© www.soinside.com 2019 - 2024. All rights reserved.