当我有常规方法可以调用类中的另一个方法时,我必须这样做
class test:
def __init__(self):
pass
def dosomething(self):
print "do something"
self.dosomethingelse()
def dosomethingelse(self):
print "do something else"
但是当我有静态方法时我不能写
self.dosomethingelse()
因为没有实例。在 Python 中从同一个类的另一个静态方法调用静态方法需要做什么?
最佳答案
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()
关于python - 静态方法 - 如何从另一个方法调用一个方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1859959/