4 ms·
I never thought much about best implementation because I only used it i think once in ten years. But afaik I used something like this, that does the job and is
by smoe 9y ago
I never thought much about best implementation because I only used it i think once in ten years. But afaik I used something like this, that does the job and is easy to read
_empty = object()
def deep_get(dct, dotted_path, default=_empty):
for key in dotted_path.split('.'):
try:
dct = dct[key]
except KeyError:
if default is _empty:
raise
return default
return dct