'''
迭代器
1.什么是迭代器? 器,即工具, 迭代,是指不断地更新换代,例如某种应用程序的版本从1.0更新到2.0,再到3.0,这个过程就是迭代
迭代器就是,根据上一个结果得到下一个结果的工具,简单来说就是一种获取数据的工具
可迭代对象:是指可以使用迭代器取出数据的对象
判断一个对象是否是可迭代的,就要看这个对象是否提供迭代器
'''
# def register(username, password, conf_password, balance):
# with open(r'C:python总文件夹python练习代码作业作业a.txt', 'r', encoding='utf-8') as f:
# for line in f:
# if line.strip('
').split('|')[0] == username:
# return False, '用户已存在'
#
# if not balance.isdigit(): return False, '金额必须是数字'
#
# if password == conf_password:
# user_info = '|'.join([username, password, balance]) + '
'
# with open(r'C:python总文件夹python练习代码作业作业a.txt', 'a', encoding='utf-8') as f:
# f.write(user_info)
# f.flush()
# return True, '注册成功'
# else:
# return False, '两次密码不一致!'
#
#
# while True:
# username = input('请输入用户名:').strip()
# password = input('请输入密码:').strip()
# conf_password = input('请确认密码:').strip()
# balance = input('请输入金额:').strip()
#
# flag, msg = register(username, password, conf_password, balance)
# if flag:
# print(msg)
# break
# else:
# print(msg)
user_info = {}
def login_auth(func):
def wrapper(*args, **kwargs):
global user_info
if user_info:
res = func(*args, **kwargs)
return res
else:
# login()
with open('auth_db', 'r', encoding='utf-8') as f:
user_dic = eval(f.read())
if user_dic['name'] == 'tank' and user_dic['password'] == '123':
user_info = user_dic
print('登录成功!')
return wrapper
@login_auth
def shopping():
print('shopping...')
@login_auth
def withdraw():
print('withdraw...')
@login_auth
def repay():
print('repay...')
shopping('tank','123')