标签:__call__ __init__ UNC ini int 用法 *args name sel
__call__的用法
class Test(object):
def __call__(self):
print("---call---")
t = Test()
t()
输出
---call---
类装饰器
class Test(object):
def __init__(self,func):
self.__func = func
print("func name is %s"%func.__name__)
def __call__(self, *args, **kwargs):
self.__func()
#这里的@Test相当于test = Test(test)
@Test
def test():
print("---test---")
test()
输出
func name is test ---test---
标签:__call__ __init__ UNC ini int 用法 *args name sel
原文地址:https://www.cnblogs.com/xone/p/10274899.html