Skip to content Skip to sidebar Skip to footer

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

Solution 1:

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

Solution 2:

Note that iteris available in Python 2.6 (and even 2.5 - otherwise, there'd be a notice in the docs), so you don't really need a replacement.

You can, however, use findall:

def_iter_python26(node):
  return [node] + node.findall('.//*')

Post a Comment for "Elementtree's Iter() Equivalent In Python2.6"