pyth error [rtf to xml/html]



我正在尝试使用python 3.6.1将RTF转换为XML/xhtml。

蟒蛇代码: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:xxfile1.py", line 14, in <module>
from pyth.plugins.rtf15.reader import Rtf15Reader
File "C:Python 3.6.1libsite-packagespythpluginsrtf15reader.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版本。

附注: 在您的示例代码中,

print XHTMLWriter.write(doc, pretty=True).read()

是 Python 2.x 版本,而不是 Python 3.x 版本。请检查。

pyth包现在也可用于python3。安装pyth3包:

py -3 -m pip install pyth3

最新更新