修饰器-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()
posted @ 2018-08-12 19:45  亚格斯123  阅读(163)  评论(0编辑  收藏  举报