【发布时间】:2011-01-12 17:52:31
【问题描述】:
我知道有这样的情况是有道理的,但不知何故我有它:
class foo
#static method
@staticmethod
def test():
pass
# class variable
c = {'name' : <i want to reference test method here.>}
怎么走?
仅作记录:
我认为这应该被视为 python 最糟糕的做法。如果有的话,使用静态方法并不是真正的 pythoish 方式......
【问题讨论】:
-
如果可能,您应该考虑使用新式类。
-
另外,请注意
staticmethod通常不应使用。 Python 为这个应用程序提供了正常的功能。 -
这仍然不是语法有效的python
标签: python static-methods class-variables