装饰器模拟访问页面
#coding:utf-8 list=[{'name':'alex','passwd':'123123'}, {'name':'tom','passwd':'123123'}] current={'name':None,'passwd':False} def timmer(func): def wrapper(): if current['name'] and current['passwd'] : func() return 1 else: name=input("请输入用户名: ") passwd=input("请输入你的密码: ") for i in list: if i['name'] == name and i['passwd']== passwd : current['name']=name current['passwd']=True func() return 1 else : print("你输入的用户名或者密码错误") return wrapper @timmer def index(): print("欢迎来到京东首页") @timmer def home(): print("欢迎来到家目录") index() print(current) home()
I can feel you forgetting me。。 有一种默契叫做我不理你,你就不理我