Python 在 class 中引用静态方法 - 最佳实践

Python referencing static methods within a class - best practise

这只是一个 "Is there a better way of doing x?" 关于 classes 中使用 python 的 @staticmethod 函数的问题。

我有以下内容:

class my_class():
    @staticmethod
    def function_a():
        print("hello")

    @staticmethod
    def function_b():
        my_class.function_a()

显然对于静态 classes 你没有 "self" 引用,但是还有另一种方法可以在 class 中引用函数而不使用 class 名称 "my_class.xxxxx"?

大多数其他语言都有不同的版本,例如 php 有 $this-> 继承和 self:: 静态。

my_class.function_b 应该是 classmethod:

@classmethod
def function_b(cls):
    cls.function_a()

class 方法将对调用它们的 class(或调用它们的实例的 class)的引用作为第一个参数传递,而不是通常的 self.