python - Python2.6 中 ElementTree 的 iter() 等价物

标签 python xml python-2.6 elementtree

我的 ElementTree 代码在 Python 2.7 中运行良好。 我需要在“X/Y”节点下获取名称为“A”的所有节点。

from xml.etree.ElementTree import ElementTree

verboseNode = topNode.find("X/Y")
nodes = list(verboseNode.iter("A"))

但是,当我尝试使用 Python 2.6 运行它时,出现了这个错误。

ionCalculateSkewConstraint.py", line 303, in getNodesWithAttribute
    nodes = list(startNode.iter(nodeName))
AttributeError: _ElementInterface instance has no attribute 'iter'

看起来 Python 2.6 ElementTree 的节点没有 iter()。 如何使用 Python 2.6 实现 iter()?

最佳答案

不确定这是否是您要查找的内容,因为 iter() 似乎在 2.6 中出现,但是有 getiterator()

http://docs.python.org/library/xml.etree.elementtree.html#xml.etree.ElementTree.Element.getiterator

关于python - Python2.6 中 ElementTree 的 iter() 等价物,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7616800/

相关文章:

python2.6.6 将apache日志时间戳转换为纪元以来的秒数(unix风格)

python - 我可以按 2 个键对对象列表进行排序吗?

python - Linux。 Heroku-Django。 Collectstatic 只读文件系统

Python:heapq.heappop() 给出奇怪的结果

python - 对多列进行分组并过滤并拆分为单独的数据帧

python - 使用 ElementTree 跟踪父元素

php - 如何在 PHP 中捕获未设置的 REQUEST 值

python解析/处理文件夹中的所有xml文件

xml - 如何使用 Xpath 从 BoxOfficeMojo 中提取电影标题

python - 如何以特定用户身份调用 Python 脚本中存在的命令