Python 在类的静态函数中调用另一个静态函数

有两种常见解决办法:

  1. 调用目标函数的__func__()方法。
  2. 使用CLASS_NAME.target_func()方法。这种方法更加干净、Pythonic。
1
2
3
4
5
6
7
8
9
10
11
class Klass(object):

@staticmethod # use as decorator
def stat_func():
return 42

_ANS = stat_func.__func__() # call the staticmethod

def method(self):
ret = Klass.stat_func()
return ret