-
-
Save lithium/908455 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 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