I am using xml.etree
in Python to parse a SOAP response (don't ask...). The response contains a <Success />
element.
I go and search it, find it and get an xml.etree.ElementTree.Element
instance, let's call it my_element
.
Yet said instance evaluates to False
bool(my_element)
is Falsemy_element.__nonzero__()
isFalse
(using Python 2.7, otherwise I'd check__bool__()
of course).
I assume that is because my_element.text
is empty, as <Success />
is an empty xml element.
I also assume this is a pythonic thing to do, as empty lists and dicts behave similarly - even though I think the meaning of an empty but existing XML element is different: What is the most pythonic way to check whether it is there?
Is it really the following?
from xml.etree.ElementTree import Element
...
if isinstance(my_element, Element):