class Registry:
def __init__(self):
self._functions=
[]
def register(self,decorated):
self._functions.append(decorated)
return decorated
def run_all(self,*args,**
kwargs):
return_values=
[]
for func
in self._functions:
return_values.append(func(*args,**
kwargs))
print(return_values)
return return_values
a=
Registry()
b=
Registry()
@a.register
def foo(x=3
):
return x
@b.register
def bar(x=5
):
return x
@a.register
@b.register
def baz(x=7
):
return x
a.run_all(x=5
)
b.run_all()
转载于:https://www.cnblogs.com/xuyuchen/p/8504731.html
转载请注明原文地址: https://win8.8miu.com/read-2853.html