diff --git a/untangle.py b/untangle.py index 54dee14..64269f0 100755 --- a/untangle.py +++ b/untangle.py @@ -80,7 +80,14 @@ def __getattr__(self, key): self.__dict__[key] = matching_children return matching_children else: - raise IndexError('Unknown key <%s>' % key) + raise AttributeError( + "'%s' has no attribute '%s'" % (self._name, key) + ) + + def __hasattribute__(self, name): + if name in self.__dict__: + return True + return any(self.children, lambda x: x._name == name) def __iter__(self): yield self