diff --git a/attributedict/collections.py b/attributedict/collections.py index 84ceb26..73e2d7e 100644 --- a/attributedict/collections.py +++ b/attributedict/collections.py @@ -223,6 +223,30 @@ def __getattr__(self, key): return self.__getitem__(key) except Exception as error: + for existing_key in self.__dict__: + if existing_key.startswith(key + '.'): + class _DottedKey(object): + def __init__(self, target, prefix): + self.target = target + self.prefix = prefix + + def __getattr__(self, child_key): + target = self.__dict__['target'] + prefix = self.__dict__['prefix'] + child_full_key = '{0}.{1}'.format(prefix, child_key) + + try: + return target.__getitem__(child_full_key) + + except Exception as child_error: + for existing in target.__dict__: + if existing.startswith(child_full_key + '.'): + return _DottedKey(target, child_full_key) + + raise AttributeError(child_error) + + return _DottedKey(self, key) + raise AttributeError(error) def __setattr__(self, key, value):