Calling member functions?

Oleg Broytmann phd at phd.pp.ru
Thu Dec 13 12:34:46 CET 2001


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.

> 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!

Oleg.
-- 
     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 mailing list