Skip to content

Instantly share code, notes, and snippets.

@h2rd
Created November 15, 2013 21:22
Show Gist options
  • Select an option

  • Save h2rd/7491861 to your computer and use it in GitHub Desktop.

Select an option

Save h2rd/7491861 to your computer and use it in GitHub Desktop.
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