I would like to iterate through an XML structure. My code does seem to work. I checked the debugger and saw that it reached the return, but the for loop continues.
Looking forward to your advice, thank you!
def get_value(root, item):
for node in root:
if node.tag == item:
return node.tag
else:
get_value(node, item)
return 'Item not found in XML'
return. You must have seen the previous recursive calls completing.returnstatement was encountered no further iterations of yourforloop would execute. Note that your function is recursive so be mindful of that when stepping through the debugger.return, see my answer on this question.else:condition to be doing (you make a recursive call and ignore the return value). If you actually reach areturn, the function always returns immediately unless: 1) The expression associated with thereturntriggers an exception (e.g.nodehas notagattribute) or 2) There is awithortry/finallyinvolved, in which casewith/finallycleanup happens first. Why do you think the loop continues after thereturn?