What is the difference between the following class methods?
Is it that one is static and the other is not?
class Test(object): def method_one(self): print 'Called method_one' def method_two(): print 'Called method_two' a_test = Test() a_test.method_one() a_test.method_two()
In Python, there is a distinction between bound and unbound methods.
Basically, a call to a member function (like
method_one), a bound functionis translated to
i.e. a call to an unbound method. Because of that, a call to your version of
method_twowill fail with aTypeErrorYou can change the behavior of a method using a decorator
The decorator tells the built-in default metaclass
type(the class of a class, cf. this question) to not create bound methods formethod_two.Now, you can invoke static method both on an instance or on the class directly: