Skip to content

Instantly share code, notes, and snippets.

@ruoyu0088
Created February 20, 2015 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruoyu0088/b0ad5b1938d78010566c to your computer and use it in GitHub Desktop.
Save ruoyu0088/b0ad5b1938d78010566c to your computer and use it in GitHub Desktop.
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