user_id={'name':None,'passwd':False}def test(func): def wrapper(*args,**kwargs): if user_id['name'] and user_id['passwd']: res=func(*args,**kwargs) return res name=input('请输入用户名: ') passwd=input('请输入密码: ') if name=='alex' and passwd=='123456': user_id['name']=name user_id['passwd']=True res=func(*args,**kwargs) return res else: print('您输入的用户名或者密码错误!') return wrapper@testdef index(): print('欢迎用户登陆')index()---------------------------------------------------------------------------------请输入用户名: alex请输入密码: 123456欢迎用户登陆
来源:https://www.cnblogs.com/cxydnxs/p/12291038.html