Passing a method indirectly

Farshid Lashkari flashkNO at SPAMgmail.com
Sun Mar 5 01:19:47 CET 2006


You don't need to pass the object along with the method. The method is 
bound to the object. Simply call the method by itself:

def ObjApply(method):
	method()

class Test:
	def test1 (self): print "Hello"
	def test2 (self):
		ObjApply(self.test1)

ta = Test ()
ta.test2 ()

If you wanted to pass an unbound method, then it would look like the 
following:

def ObjApply(object,method):
	method(object)

class Test:
	def test1 (self): print "Hello"
	def test2 (self):
		ObjApply(self,Test.test1)

ta = Test ()
ta.test2 ()



More information about the Python-list mailing list