[英]Import error when using XPath from PyXML-0.8.4
I'm learning Xpath and XSLT using Python 2.6.6-64bit on my unix workstation. 我正在unix工作站上使用Python 2.6.6-64bit学习Xpath和XSLT。 For Xpath, I'm using the xpath module provided in PyXml-0.8.4. 对于Xpath,我使用的是PyXml-0.8.4中提供的xpath模块。
However, the import line itself throws the following error: 但是,导入行本身会引发以下错误:
Traceback (most recent call last):
File "xp.py", line 7, in <module>
from xml.xpath import Evaluate
File "/usr/local/python-2.6.6-64bit/lib/python2.6/site-packages/_xmlplus/xpath/__init__.py", line 112, in <module>
from pyxpath import ExprParserFactory
File "/usr/local/python-2.6.6-64bit/lib/python2.6/site-packages/_xmlplus/xpath/pyxpath.py", line 59, in <module>
from xml.xpath.ParsedAbbreviatedRelativeLocationPath import ParsedAbbreviatedRelativeLocationPath
File "/usr/local/python-2.6.6-64bit/lib/python2.6/site-packages/_xmlplus/xpath/ParsedAbbreviatedRelativeLocationPath.py", line 31
as = ParsedAxisSpecifier.ParsedAxisSpecifier('descendant-or-self')
^
SyntaxError: invalid syntax
Looking it up led me to understand that this is because 'as' is a reserved name in python-2.6 and PyXML-0.8.4 tries to redefine it. 查找它使我理解这是因为“ as”是python-2.6中的保留名称,而PyXML-0.8.4试图重新定义它。 However, there are no directions on how to resolve this issue. 但是,没有有关如何解决此问题的说明。
Please advise. 请指教。
PyXML is obsolete and should not be used (see here ). PyXML已过时,不应使用(请参阅此处 )。 That's why there are no updates for it. 这就是为什么没有更新的原因。 Many features that were included in it were added to Python's standard library. 其中包含的许多功能已添加到Python的标准库中。 There are also fully-supported third-party packages for Python XML processing like lxml . 也有用于Python XML处理的完全支持的第三方程序包,例如lxml 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.