Created
November 15, 2013 21:22
-
-
Save h2rd/7491861 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 Observable(object): | |
| def __init__(self, **kwargs): | |
| for key, val in kwargs.items(): | |
| setattr(self, key, val) | |
| def __format(self): | |
| attrs = ['%s=%s' % (key, val) | |
| for key, val in self.__dict__.iteritems() if not key.startswith('_')] | |
| return 'Observable(%s)' % (', '.join(attrs)) | |
| def __str__(self): | |
| return self.__format() | |
| def __repl__(self): | |
| return self.__format() | |
| class X(Observable): | |
| pass | |
| if __name__ == '__main__': | |
| o = X(foo=1, bar=5, _bazz=12, | |
| name='Amok', props=('One', 'two')) | |
| print(o) | |
| print(o.foo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment