Try changing
for part in self.root.findall('part_list'):
to
for part in self.root.find('part_list'):
findall
returns a list of all the nodes that match. So, the first line returns a list of all the part_list
nodes. Your <part_list>
node doesn't have any children with the tag part_type
, so it returns None
, and you get your error.
If you have a single node part_list
, then find
will return the actual node, and you can use the normal for part in
syntax to walk over all of its subnodes instead.
If you have multiple part_list
tags, then you just need a nested for loop:
for part_list in self.root.findall('part_list'):
for part in part_list:
etc.
Edit: Given that this was sort of an XY problem - if what you are looking for is really a particular subpath, you can do that all at once, like this:
all_parts = self.root.findall('part_list/part')
print all_parts[0].find('part_type').tag
etc.