How to call static methods inside one class in python

I have two static methods in one class

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

    @staticmethod
    def methodB():
        print 'methodB'

What can I call methodAinside methodB? selfseems unavailable in a static method.

+4
source share
1 answer

In fact, selfnot available in static methods. If @staticmethoddecoration was used instead @classmethod, the first parameter will be a reference to the class itself (usually called cls). But despite 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()
+4
source

Source: https://habr.com/ru/post/1629198/


All Articles