修饰器-2
Posted gaoxu366
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了修饰器-2相关的知识,希望对你有一定的参考价值。
import time
user,passwd = "gx","gx123"
def auth(func):
def wrapper(*args,**kwargs):
username = input("username:").strip()
password = input("password:").strip()
if user == username and passwd == password:
print("you has passed")
f = func(*args,**kwargs)#func执行后没有返回值,没有传给谁
print(f)
else:
exit("you are wrong")
return wrapper
def index():
print("welcome to the index")
@auth
def home():
print("welcome to the home")
return "from home" #print(f),这时候return值传给了f,所以from home就显示出来了
@auth
def bbs():
print("welcome to the bbs")
index()
home() #调用home == 调用 wrapper
bbs()
以上是关于修饰器-2的主要内容,如果未能解决你的问题,请参考以下文章