How to call static methods inside the same class in python

In fact, the self is not available in static methods. If the decoration @classmethod was used instead of @staticmethod the first parameter would be a reference to the class itself (usually named as cls). But despite of all this, inside the static method methodB() you can access the static method methodA() directly through the class name:

@staticmethod
def methodB():
    print 'methodB'
    A.methodA()

As @Ismael Infante says, you can use the @classmethod decorator.

class A:
    @staticmethod
    def methodA():
        print 'methodA'

    @classmethod
    def methodB(cls):
        cls.methodA()

Tags:

Python