需要注意的:
函数先定义,再修饰它;反之会编译器不认识;
修饰符“@”后面必须是之前定义的某一个函数;
每个函数只能有一个修饰符,大于等于两个则不可以。
def test(f):
print "before ..."
f()
print "after ..."
@test
def func():
print "func was called"
输出:
before ...
func was called
after ...
需要注意的:
函数先定义,再修饰它;反之会编译器不认识;
修饰符“@”后面必须是之前定义的某一个函数;
每个函数只能有一个修饰符,大于等于两个则不可以。
def test(f):
print "before ..."
f()
print "after ..."
@test
def func():
print "func was called"
输出:
before ...
func was called
after ...