我是 python 的新手,所以请原谅从其他语言中窃取的命名法。我有一个包含“静态”属性(列表)和静态方法的类。我想初始化参数以仅包含对该方法的引用:
class LogFilter(object):
@staticmethod
def _process_friendly_time(params):
# process params
pass
param_processors = [
LogFilter._process_friendly_time
]
# Later
for processor in LogFilter.param_processors:
processor(params)
此代码导致错误
NameError: name 'LogFilter' is not defined`.
但是如果我LogFilter._process_friendly_time用刚才替换_process_friendly_time我以后会得到一个错误......
TypeError: 'staticmethod' object is not callable
是否有一种语法可以让我这样做,或者我必须将静态方法移到类之外?
qq_花开花谢_0
相关分类