首页 > 其他 > 详细

修饰器-2

时间:2018-08-12 20:35:00      阅读:148      评论:0      收藏:0      [点我收藏+]
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

原文:https://www.cnblogs.com/gaoxu366/p/9464079.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!