Observer-Pattern by (simple) decorator
Wildemar Wildenburger
wildemar at freakmail.de
Fri Jun 1 20:25:50 EDT 2007
Steven Bethard wrote:
> I think you want to define __get__ on your Observable class so that it
> can do the right thing when the method is bound to the instance:
>
> >>> class Observable(object):
> [snip]
> ... def __get__(self, obj, cls=None):
> ... if obj is None:
> ... return self
> ... else:
> ... func = self.func.__get__(obj, cls)
> ... return Observable(func, obj, self.observers)
> [snip]
Great, that does it! Thanks a billion :)
It took me quite some time understanding what the __get__ method does,
but I think now I figured it out. I've made a quantum leap in my
understanding of Python (esp. method binding) with this! Awesome!
:)
/W
More information about the Python-list
mailing list