【问题标题】:Convert .rtf file to sting output - how to remove /par from string output?将 .rtf 文件转换为字符串输出 - 如何从字符串输出中删除 /part?
【发布时间】:2021-07-12 06:17:47
【问题描述】:
with open('myfile.rtf', 'r') as file:
    text = file.read()
print(text)

我已经尝试过这段代码,但它存在的问题是,在.rtf 文件中的数据输入过程中,每次按下 Enter 都会打印一个 \par。有人可以帮我从字符串输出中删除 '\par' 吗?

【问题讨论】:

  • RTF 文件可以有更多的标签。您可能想查看read_rtf 模块。

标签: python python-3.x file-handling


【解决方案1】:
with open('myfile.rtf', 'r') as file:
      text = file.read()
from striprtf.striprtf import rtf_to_text
rtf = text
text1 = rtf_to_text(rtf)
print(text1)

在终端中,请在执行上述代码之前使用此代码pip install striprtf

使用此代码,您还可以获取带有.rtf 扩展名的文件并生成str 输出

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-01
    • 1970-01-01
    • 2011-03-04
    • 2018-05-16
    相关资源
    最近更新 更多