[Python] 纯文本查看 复制代码 # 装饰器实现登入
loggin_status = False
user_dict = {}
# 数据库密码 文件格式
# user_db
# king=123456
# def login():
# global loggin_status
# user = input('user:')
# passwd = input('password:')
# if user == 'king' and passwd == '123456':
# print("登陆成功!!!")
# loggin_status = True
# else:
# print("密码错误!!!!")
# loggin_status = False
def login():
global loggin_status
user = input('user:')
password = input('password:')
with open('user_db', 'r', encoding='utf-8') as file:
for line in file.readlines():
u, p = line.strip().split('#')
if user == u and password == p:
print("登陆成功!!!")
loggin_status = True
break
else:
print("用户密码错误!!!")
loggin_status = False
def loggin(func):
def warpper(*args, **kwargs):
if not loggin_status:
login()
func()
return warpper
@loggin
def shouji():
print('this pages is shouji')
@loggin
def dianqi():
print('this pages is dianqi')
while True:
print('''
欢迎使用
1.手机
2.电气
3.退出
''')
a = int(input('>>'))
if a in range(1, 4):
if a == 1:
shouji()
if loggin_status is False:
print('loggin_status为False')
else:
print('loggin_status为Ture')
elif a == 2:
dianqi()
elif a == 3:
break
else:
print('不再范围内....')
|