#装饰器
def log(func):
def warp(*args, **kwargs):
print("添加日志开始")
res = func(*args,**kwargs)
print("添加日志结束")
return res
return warp()
@log
def delte():
print("删除操作")
delte
带参数拦截器
def log(i):
def warp1(func):
def warps2(*args, **kargs):
print("日志记录开始")
if i > 0:
print("拥有权限")
else:
print("权限不足")
func(*args, *kargs)
print("日志记录结束")
return warps2
return warp1
@log(2)
def deleteuser(*args):
print("删除用户%s成功"%(args))
deleteuser(["kemuchao","123"])