Skip to content

Instantly share code, notes, and snippets.

@deepgully
Created January 24, 2014 14:37
Show Gist options
  • Save deepgully/8598463 to your computer and use it in GitHub Desktop.
Save deepgully/8598463 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
class MagicDict(dict):
def __init__(self, **kwargs):
dict.__init__(self, kwargs)
self.__dict__ = self
def __getattr__(self, name):
self[name] = MagicDict()
return self[name]
if __name__ == "__main__":
c = MagicDict()
c.people.name = 'roy'
c.test1.test2.test3 = "test3"
print(c)
print(c.people)
print(c.people.name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment