How to use decorator in observer pattern for Python 2.7
问题 The observer pattern in the very simplified code below works well. I would like to have have a decorator @on_event that does the registration in the Observable singleton. In class O2 below this does not work. The problem is of course that the decorator on_event get's called prior to the instance is created, and the registration will be to the unbound method event . In some way I have to delay the registration until the O2 object is initialized. Maybe needless to say but all I want to add in