Created
February 20, 2015 12:39
-
-
Save ruoyu0088/b0ad5b1938d78010566c 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 AttrDict(dict): | |
def __getattr__(self, attr): | |
return self[attr] | |
def __setattr__(self, attr, value): | |
if isinstance(value, dict): | |
value = AttrDict(value) | |
self[attr] = value | |
p = AttrDict() | |
p.x = 1 | |
p.y = 2 | |
p.v = {} | |
p.v.x = 3 | |
p.v.y = 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment