Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ElementTree's iter() equivalent in Python2.6

I have this code with ElementTree that works well with Python 2.7. I needed to get all the nodes with the name "A" under "X/Y" node.

from xml.etree.ElementTree import ElementTree

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

However, when I tried to run it with Python 2.6, I got this error.

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

It looks like that Python 2.6 ElementTree's node doesn't have the iter(). How can I implement the iter() with Python 2.6?

like image 221
prosseek Avatar asked Sep 30 '11 22:09

prosseek


1 Answers

Not sure if this is what you are looking for, as iter() appears to be around in 2.6, but there's getiterator()

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

like image 127
Adam Wagner Avatar answered Oct 13 '22 23:10

Adam Wagner