FileNotFoundError:rtfparser python 包

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

任何有过这个包经验的人,我已经尝试了很多东西但它不起作用,我已经检查过该文件是否存在很多次,绝对|相对路径,不起作用

D:\pythonCodePycharmProjects\carProject\venv\Scripts\python.exe D:\pythonCodePycharmProjects\carProject\main.py 
Traceback (most recent call last):
  File "D:\pythonCodePycharmProjects\carProject\main.py", line 10, in <module>
    parsed = parser.parse_file()
             ^^^^^^^^^^^^^^^^^^^
  File "D:\pythonCodePycharmProjects\carProject\venv\Lib\site-packages\rtfparse\parser.py", line 66, in parse_file
    file = open(self.rtf_path, mode="rb")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'D:\\pythonCodePycharmProjects\\carProject\\rtf\\test.rtf'

Process finished with exit code 1
import pathlib
from rtfparse.parser import Rtf_Parser
from rtfparse.renderers import de_encapsulate_html

source_path = pathlib.Path(r"D:\pythonCodePycharmProjects\carProject\rtf\test.rtf")
target_path = pathlib.Path(r"D:\pythonCodePycharmProjects\carProject\rtf\test.html")


parser = Rtf_Parser(rtf_path=source_path)
parsed = parser.parse_file()


renderer = de_encapsulate_html.De_encapsulate_HTML()
with open(target_path, mode="w", encoding="utf-8") as html_file:
    renderer.render(parsed, html_file)
python pip rtf
1个回答
0
投票

你为什么使用r“你的路径”?您是否尝试过像“”或''这样的简单字符串或像f“”这样的格式化字符串?

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