class Observer(object): def __init__(self): super().__setattr__('_subscribers', {}) def subscribe(self, name, cb): if name not in self._subscribers: self._subscribers[name] = [] self._subscribers[name].append(cb) def __setattr__(self, name, val): if name in self._subscribers: for cb in self._subscribers[name]: cb(val) super().__setattr__(name, val)