# 多个函数被装饰后 只要有一次认证成功 之后就不需要认证
is_auth = {'is_login':False}
def login_auton(func_name):
def inner(*args, **kwargs):
if is_auth.get('is_login'):
res = func_name(*args, **kwargs)
return res
name = input('name>>>:').strip()
code = input('code>>>:').strip()
if name =='bob' and code == '123':
res = func_name(*args, **kwargs)
is_auth['is_login'] = True
return res
else:
print('用户名或密码错误')
return inner
@login_auton
def index():
print('from index')
@login_auton
def home():
print('from home')
@login_auton
def func():
print('from func')
index()
home()
func()
'''在日常生活中 比如很多网站的登录 只要成功一次 之后很长时间都不需要再次登录'''