ElementTree's iter() equivalent in Python2.6

后端 未结 2 2020
日久生厌
日久生厌 2021-01-08 00:54

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.Elem         


        
相关标签:
2条回答
  • 2021-01-08 01:28

    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

    0 讨论(0)
  • 2021-01-08 01:30

    Note that iter is 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('.//*')
    
    0 讨论(0)
提交回复
热议问题