Reputation: 105
There is a function of the xml.etree.ElementTree module to do that? NOT:
if node.find(tag)!=None:
#code
pass
Upvotes: 0
Views: 533
Reputation: 474191
That's exactly what you've presented. find()
is the tool for the job:
Finds the first subelement matching match. match may be a tag name or path. Returns an element instance or
None
.
It's just that, to follow the best practices, use is
when comparing to None
:
if node.find(tag) is not None:
# code
Upvotes: 3