# 装饰器
def new_func(func):
def wrappedfunc(username, password):
if username == "root" and password == "123":
print("Validation passed")
return func()
else:
print("Wrong username or password")
return
return wrappedfunc
@new_func
def run():
print("Start execution")
run("root", "123")
输出为:
Validation passed
Start execution
run("root", "456")
输出为:
Wrong username or password