Calling member functions?
david_j_dawkins at spamless.hotmail.com
Thu Dec 13 13:22:17 CET 2001
"Oleg Broytmann" <phd at phd.pp.ru> wrote in message
news:mailman.1008243437.6415.python-list at python.org...
> On Thu, Dec 13, 2001 at 11:20:52AM -0000, David Dawkins wrote:
> > class Handler:
> > def Callback(self):
> > print "Callback called"
> > class Notifier:
> > def __init__(self, object, method):
> > self.m_object = object
> > self.m_method = method
> > def notify(self):
> > ## Now what??
> > self.m_method(self.m_object) ## naive attempt
> ^^^^^^^^ You call a method with one argument, but the
> Callback method does not accept any arguments.
but then how does Handler.Callback receive its own "self" value? In this
call, "self" is an instance of Notifier. Handler.Callback must receive an
instance of Handler, which is stored in self.m_object.
> > h = Handler()
> > n = Notifier( h, h.Callback )
> > h.notify() # I want this to do h.Callback() in effect
> h.notify()? You certainly meant n.notify()! Other than that you naive
> attempt is pretty close!
You're right, I made a typo as I created the example for this posting.
> Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru
> Programmers don't die, they just GOSUB without RETURN.
More information about the Python-list