python - 从类变量引用静态方法

标签 python static-methods class-variables

我知道有这样的情况是有线的,但不知何故我有:

class foo
  #static method
  @staticmethod
  def test():
    pass

  # class variable
  c = {'name' : <i want to reference test method here.>}

它的出路是什么?

仅作记录:

我认为这应该被视为 Python 最糟糕的做法。如果曾经使用静态方法并不是真正的 pythoish 方式......

最佳答案

class Foo:
    # static method
    @staticmethod
    def test():
        pass

    # class variable
    c = {'name' : test }

关于python - 从类变量引用静态方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2194185/

相关文章:

python - 为什么 imaplib 在每封电子邮件后返回一个单独的括号?

python - 为什么人们在 __get__ 中将 owner 参数默认为 None?

matrix - 如何在实现中缀运算符时避免循环依赖

java - 我的静态变量能活多久?

ruby - ruby 中的实例变量就像类变量

python - 可变和不可变类变量如何初始化?

Python 和 ReportLab : add a string at the end of every page

python - 将错误异常保存到文件错误中

Python:单独的实用程序文件或使用静态方法?

ruby - 如何从 ruby​​ 中的外部访问类变量?