2019-11-28 13:30:11 +08:00
|
|
|
|
|
|
|
from functools import partial
|
|
|
|
from appPublic.Singleton import SingletonDecorator
|
|
|
|
|
|
|
|
@SingletonDecorator
|
|
|
|
class RegisterFunction:
|
|
|
|
def __init__(self):
|
|
|
|
self.registKW = {}
|
|
|
|
|
|
|
|
def register(self,name,func):
|
|
|
|
self.registKW[name] = func
|
|
|
|
|
|
|
|
def get(self,name):
|
|
|
|
return self.registKW.get(name,None)
|
|
|
|
|
2019-11-29 11:34:44 +08:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
def x(a):
|
|
|
|
print('x():a=',a)
|
|
|
|
|
|
|
|
def y(a):
|
|
|
|
print('y():a=',a)
|
|
|
|
|
|
|
|
def z():
|
|
|
|
rf = RegisterFunction()
|
|
|
|
for name in ['func1', 'func2' ]:
|
|
|
|
f = rf.get(name)
|
|
|
|
print(name,f('hahah'))
|
|
|
|
|
|
|
|
rf = RegisterFunction()
|
|
|
|
rf.register('func1',x)
|
|
|
|
rf.register('func2',y)
|
|
|
|
z()
|