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

zealalot zealalot at gmail.com
Fri May 1 11:11:01 EDT 2009


On May 1, 10:50 am, CTO <debat... at gmail.com> wrote:
> 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)

It's not surprising, but I've never heard of a classmethod before.
Basically, I read that it basically removes the need for the 'self'
argument.  Very cool!

And thanks for the quick response,

- Zealalot



More information about the Python-list mailing list