Skip to content

Instantly share code, notes, and snippets.

@slpsys
Created May 5, 2011 23:49
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 slpsys/958211 to your computer and use it in GitHub Desktop.
Save slpsys/958211 to your computer and use it in GitHub Desktop.
class Stuff:
dict = {}
def __getattr__(self, key):
if not key:
return self
elif self.dict.has_key(key):
return self.dict[key]
raise AttributeError,key
def __setitem__(self, key, value):
self.dict[key] = value
def __init__(self, *args, **arg_dict):
for k, v in arg_dict.iteritems():
self.dict[k] = v
stuff = Stuff(a=1, b=2, c=3)
print stuff.b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment