login_status_jingdong = False login_status_weixin = False def start(): list = {1: 'home', 2: 'finance', 3: 'book'} list1 = {1: home, 2: finance, 3: book} for i in list: print(i, list[i]) select_num = input('请输入访问网页的编号[退出:q]>>') if select_num == 'q': return exit() elif select_num.isdigit(): key = int(select_num) list1[key]() else: print('请输入有效值!') def login(types = ""): def outers(a): def inner(): global login_status_jingdong global login_status_weixin if types == "jingdong": if login_status_jingdong is False: with open("jingdong","r",encoding="utf8") as f1: d1={} for i in f1.readlines(): [key,valus] = i.split("=") d1[key]=valus.strip() print(d1) username = input("输入用户名:").strip() # 通过分隔符将字符串转为列表,并赋值给变量key和valus password = input("输入密码:").strip() # 向字典中添加元素,这步就实现了字符串转为列表的功能 if username == d1["username"] and password == d1["password"]: login_status_jingdong = True a() else: print("账号或密码错误") return inner return outers @login('jingdong') def home(): print('welcome to home page') @login('weixin') def finance(): print('welcome to finance page') @login('jingdong') def book(): print('welcome to book page') while True: start()