我正在尝试使用 python 3.6.1 将 RTF 转换为 XML/xhtml。
Python 代码:https://github.com/brendonh/pyth/blob/master/examples/reading/rtf15.py
import sys
import os.path
from pyth.plugins.rtf15.reader import Rtf15Reader
from pyth.plugins.xhtml.writer import XHTMLWriter
if len(sys.argv) > 1:
filename = sys.argv[1]
else:
filename = os.path.normpath(os.path.join(os.path.dirname(__file__),'../../tests/rtfs/sample.rtf'))
doc = Rtf15Reader.read(open(filename, "rb"))
print(XHTMLWriter.write(doc, pretty=True).read())
错误:
Traceback (most recent call last):
File "C:\xx\file1.py", line 14, in <module>
from pyth.plugins.rtf15.reader import Rtf15Reader
File "C:\Python 3.6.1\lib\site-packages\pyth\plugins\rtf15\reader.py", line 594
match = re.match(ur'HYPERLINK "(.*)"', destination)
^
SyntaxError: invalid syntax
我可以知道如何解决语法问题吗?
谢谢。
最佳答案
请检查链接:
https://pypi.python.org/pypi/pyth/0.6.0
pyth
包仅用于 Python 2.x,不适用于 Python 3.x 版本。
PS: 在您的示例代码中,
print XHTMLWriter.write(doc, pretty=True).read()
是Python 2.x版本,而不是Python 3.x版本。请检查。
关于python - pyth 错误 [rtf 到 xml/html],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45432742/