gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 17:13:50 25 4
gpt4 key购买 nike

我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com