I am recursing through an xml file, using etree.
import xml.etree.ElementTree as etree
tree = etree.parse('x.xml')
root = tree.getroot()
for child in root[0]:
for child in child.getchildren():
for child in child.getchildren():
for child in child.getchildren():
print(child.attrib)
what is the idiomatic way in python to avoid these nested for loop.
getchildren() ⇒ list of Element instances [#]
Returns all subelements. The elements are returned in document order.
Returns:
A list of subelements.
I saw some post in SO like, Avoiding nested for loops but doesn't directly translate to my use.
thanks.