Skip to content

Instantly share code, notes, and snippets.

@torufurukawa
Created July 19, 2012 06:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torufurukawa/3141176 to your computer and use it in GitHub Desktop.
Save torufurukawa/3141176 to your computer and use it in GitHub Desktop.
DotDict
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