※ 引述《tsaiminghan (nahgnimiast)》之铭言:
: class T1(object):
: def __init__(self, func):
: self.func = func
: def __call__(self, *arg, **kw):
: print('T1:', locals())
: return self.func(*arg, **kw)
: def T2(func):
: def wrapper(*arg, **kw):
: print(locals())
: return func(*arg, **kw)
: return wrapper
讲错还请高手指正
@T1
def F():
pass
把decorator还原:
def F():
pass
F = T1(F)
F已经变成有implement call的 T1 class instance
所以在呼叫F(),locals()会带有self