Passing a function as an argument from within the same class?

CTO debatem1 at gmail.com
Fri May 1 16:50:06 CEST 2009


Make doNothing a classmethod.

class SomeClass:

    @classmethod
    def doNothing(cls):
        pass

    def function1(self):
        print "Running function 1"

    def function2(self, passedFunction=SomeClass.doNothing):
        print "Running passed function"
        passedFunction()

someObject = SomeClass()
someObject.function2()
someObject.function2(someObject.function1)





More information about the Python-list mailing list