Calling member functions?

David Dawkins david_j_dawkins at
Thu Dec 13 12:20:52 CET 2001


I can't quite get this right. How can I give an object instance and a method
as a callback for some other module/class to call at a later point?

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

h = Handler()
n = Notifier( h, h.Callback )
h.notify()  # I want this to do h.Callback() in effect

David Dawkins
david_j_dawkins  x/AT/x

More information about the Python-list mailing list