Static methods - How to call a method from another method?

Pablo picture Pablo · Dec 7, 2009 · Viewed 100.5k times · Source

When I have regular methods for calling another method in a class, I have to do this

class test:
    def __init__(self):
        pass
    def dosomething(self):
        print "do something"
        self.dosomethingelse()
    def dosomethingelse(self):
        print "do something else"

but when I have static methods I can't write

self.dosomethingelse()

because there is no instance. How do I have to do in Python for calling an static method from another static method of the same class?

Edit: what a mess. Ok, I edited back the question to the original question. I already have the answer to the second question that's in Peter Hansen's comment. If you think I should open another question for an answer I already have, plz tell me.

Answer

warvariuc picture warvariuc · Nov 5, 2010

How do I have to do in Python for calling an static method from another static method of the same class?

class Test() :
    @staticmethod
    def static_method_to_call()
        pass

    @staticmethod
    def another_static_method() :
        Test.static_method_to_call()

    @classmethod
    def another_class_method(cls) :
        cls.static_method_to_call()