import time
def logger(flag=''): #显示用flag,默认不显示
def show_time(func): #时间打印装饰器
def inner(*args,**kwargs):
func(*args,**kwargs) #所有函数可调用
print(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()))
if flag == 'true':
print('显示日志')
return inner
return show_time
h_title = eval(open('title', 'r').read())
login_flg = False
login_flg_id = ''
@logger('true')
def log_auth(s_id): #登录认证函数
global login_flg
global login_flg_id
f = eval(open(s_id, 'r').read())
if login_flg is False:
while True:
l_id = input('请输入账号:')
l_pw = input('请输入密码:')
if l_id in f.keys() and l_pw == f[l_id]:
print('登录成功')
login_flg = True
login_flg_id = s_id
break
else:
print('账号或密码错误')
def fun_title():
for t in h_title:
print(t)
while True:
fun_title()
com = input('>>>')
if com in h_title:
if login_flg is True and login_flg_id == h_title[com]:
print('进入目录', com)
elif login_flg is True and login_flg_id != h_title[com]:
print('该账号无法进入该目录')
else:
log_auth(h_title[com])
print('登录成功,进入目录', com)
elif com == 'q':
login_flg = False
else:
print('请输入正确项目')
python装饰器实例
最新推荐文章于 2023-03-05 17:03:21 发布