Skip to content

Instantly share code, notes, and snippets.

@lithium
Forked from mdellavo/struct.py
Created April 7, 2011 19:03
Show Gist options
  • Select an option

  • Save lithium/908455 to your computer and use it in GitHub Desktop.

Select an option

Save lithium/908455 to your computer and use it in GitHub Desktop.
class Struct(object):
def __init__(self, **kwargs):
self.update(kwargs)
def update(self, d):
self.__dict__.update(d)
def __repr__(self):
return 'Struct(%s)' % ', '.join('%s=%s' % (k, repr(v)) for (k,v) in
def __len__(self):
return len(self.__dict__)
def __getitem__(self, name):
return self.__dict__.get(name)
def __setitem__(self, name, value):
return self.__dict__[name] = value
def __delitem__(self, name):
del self.__dict__[name]
def __contains__(self, value):
return value in self.__dict__
def __iter__(self):
return self.__dict__.__iter__()
vars(self).items())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment