我有這個類:使用裝飾器來收集實例方法?
class Foo(object):
handlers = []
def __init__(self):
pass
def run(self):
pass
def foo(self):
pass
def bar(self):
pass
我怎麼能實現裝飾@collect_handler
class Foo(object):
handlers = []
def __init__(self):
pass
def run(self):
pass
@collect_handler
def foo(self):
pass
@collect_handler
def bar(self):
pass
使:
foo = Foo()
foo.handlers # [foo, bar]
?
這是可能的嗎?
你想'handlers'返回綁定或未綁定實例方法? – dano 2014-09-03 02:36:38
未綁定的方法 – wong2 2014-09-03 02:37:14