def login(func):
def wrapper(*args, **kwargs):
if user_list:
print('请勿重复登录')
res = func(*args, **kwargs)
return res
name_inp = input('name:')
pwd_inp = input('password:')
with open('user_info.txt', 'r', encoding='utf8') as fr:
for user_info in fr:
name, pwd = user_info.strip().split(':')
if name == name_inp and pwd == pwd_inp:
user_list.append(name)
print('登录成功!')
res = func(*args, **kwargs)
return res
else:
print('不匹配')
return wrapper
@login #add = login(add)
def add(x, y):
print(x + y)
while 1:
add(10, 20)