Browse files

update dotdict to allow for get of a dotted string

  • Loading branch information...
jeffbryner committed Jun 6, 2018
1 parent b9485a1 commit 8c5e1d0cd57853b3ff290864a1e897822e62a853
Showing with 24 additions and 0 deletions.
  1. +24 −0 lib/utilities/
@@ -17,3 +17,27 @@ def __init__(self, dct={}):
if hasattr(value, 'keys'):
value = DotDict(value)
self[key] = value
def get(self, key):
"""get to allow for dot string notation
:param str key: Key in dot-notation (e.g. '').
:return: value. None if no value was found.
return self.__lookup(self, key)
except KeyError:
return None
def __lookup(self, dct, key):
"""Checks dct recursive to find the value for key.
Is used by get() interanlly.
:param dict dct: input dictionary
:param str key: The key we are looking for.
:return: The value.
:raise KeyError: If the given key is not found
if '.' in key:
key, node = key.split('.', 1)
return self.__lookup(dct[key], node)
return dct[key]

0 comments on commit 8c5e1d0

Please sign in to comment.