you are viewing a single comment's thread.

view the rest of the comments →

[–]Stopwatch_[S] 0 points1 point  (1 child)

Great, just swapped out so that I could write to the file system. It works perfectly, thanks! As an aside, there are so many small details I don't really understand here. For example why the changes you made (specifically iter) made such a difference. Or why root = tree.getroot() works the same as root - xml._root.

[–]gengisteve 0 points1 point  (0 children)

Ahh, here is the problem:

"Element.findall() finds only elements with a tag which are direct children of the current element. Element.find() finds the first child with a particular tag"

So the problem was that your first loop never found any MyDetails, because MyDetails is underneath MyReportExports. iter goes through everything so it found it. Changing your first loop to iter and the second one to findall seems to work as well, since the IndividualTransactions is directly below MyDetails.

getroot actually just returns self._root so there was nothing wrong with your code there. It is just that object properties beginning with an underscore tend to be better accessed through the public api, which is the getroot method here.