Created
July 19, 2012 06:40
-
-
Save torufurukawa/3141176 to your computer and use it in GitHub Desktop.
DotDict
This file contains 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 DotDict(dict): | |
"""dict class that allows you to access values by dot notation""" | |
def __init__(self,arg): | |
for k in arg.keys(): | |
if (type(arg[k]) is dict): | |
self[k]=DotDict(arg[k]) | |
else: | |
self[k]=arg[k] | |
def __getattr__(self, attr): | |
return self.get(attr, None) | |
__setattr__= dict.__setitem__ | |
__delattr__= dict.__delitem__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment