-
-
Save 668/a19e928017d3a02ad170 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
# -*- 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