user_list=[{'name':'alex','passwd':'123'}, {'name':'alex','passwd':'123'}, {'name':'alex','passwd':'123'}, {'name':'alex','passwd':'123'}, {'name':'alex','passwd':'123'}, {'name':'alex','passwd':'123'},] current_dic={'username':None,'login':False} def auth_func(func): def wrapper(*args,**kwargs): if current_dic['username']and current_dic['login']: res = func(*args,**kwargs) return res username = input('用户名:').strip() passwd =input('密码:').strip() for user_dic in user_list: if username ==user_dic['name']and passwd ==user_dic['passwd']: current_dic['username']=username current_dic['login']=True res = func(*args,**kwargs) return res else: print('用户名或密码错误') return wrapper @auth_func def index(): print('欢迎来到京东商城') @auth_func def home(name): print('欢迎回家%s' %name) @auth_func def shopping_car(name): print('%s购物车里面有[%s,%s,%s]' %(name,'衣服','鞋子','饮料')) print('-------->',current_dic) index() print('---------->',current_dic) home('产品经理')