from time import ctime,sleep;
def testFunction(func):
def wrapFunction():
print "call func on %s,funcName is %s" % (ctime(),func.__name__);
return func();
return wrapFunction;
@testFunction
def foo():
print "foo is called on %s" % (ctime());
#print 123;
def exceed():
foo();
sleep(1);
foo();
exceed();
所以:
@deco1(args) #args是一个可选参数
@deco2
def func()
pass
等价于deco1(args)(deco2(func))
其中deco2至少需要定义一个函数,用来保存指向func的引用