python - 静态方法 - 如何从另一个方法调用一个方法?

标签 python static-methods

当我有常规方法可以调用类中的另一个方法时,我必须这样做

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/

相关文章:

python - 为什么非常简单的 PyTorch LSTM 模型无法学习?

java - 使用for循环在静态add方法中获取总和并将其返回给main方法

字符串上的 C++ 静态属性初始化错误

c++ - 在 C++ 中访问成员对象的方法

python - Python : bound, 未绑定(bind)和静态中的类方法差异

python - 在 Python 中创建多答案测验时遇到问题

python - while 循环内无限 while 循环

Python:如何覆盖指针位置的内存?

php - 当不在对象上下文中而不使用静态方法时使用 $this

python - Numpy 排序数组(稀疏)