Created
February 21, 2018 13:05
-
-
Save Fifan31/2b686852ef5c77da85989a9a13f74460 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DottedKeyDict(dict): | |
def get(self, path, default = None): | |
keys = path.split(".") | |
val = None | |
for key in keys: | |
if val: | |
if isinstance(val, list): | |
val = [ v.get(key, default) if v else None for v in val] | |
else: | |
val = val.get(key, default) | |
else: | |
val = dict.get(self, key, default) | |
if not val: | |
break; | |
return val |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment