class RunningLog: def __init__(self,func): self._func=func self._func_name = func.__name__ def __call__(self,func_name,level=None): self.level=level value=getattr(self, func_name.__str__())() self._func(func_name,self.level) return ‘result: ‘+value def fun(self): print ‘get value from class‘,self.level print ‘do something‘ return ‘test end‘ @RunningLog def bar(func_name,level=None): print ‘has done ‘,func_name print ‘level name===>‘,level result=bar(‘fun‘,level=‘test‘) print result
原文地址:https://www.cnblogs.com/slqt/p/10343032.html
时间: 2024-10-09 00:26:26