python装饰器TypeError: 'NoneType' object is not callable

#定义这个装饰器
def decorator(func):
print("start")
func()#运行原函数
print(func) #<function add at 0x000002167897E830>
print(func())# None
print("end")
return func #不能返回为空,所以不能用func()

@decorator
def add():
print("add")
add()




#再定义一个装饰器
def delete(func):
print("delete")
return func
#定义一个装饰器
def cal(function=None):



def decorator(func):
print("start")
# func()#运行原函数
print(func) #<function add at 0x000002167897E830>

print("end")
return func

if function==None:
return decorator
else:
return decorator(function)
#装饰的装饰
@cal(delete)
def add():
print("add")
add()

start
<function delete at 0x00000234CAA03F40>
end
delete
add




posted @ 2022-04-24 10:42  老运维  阅读(195)  评论(0)    收藏  举报