1. 程式人生 > >做一個登陸的文件操作,存到文件中是一個字典的形式{name:[pwd,tel]},為啥會報錯 ?請指點

做一個登陸的文件操作,存到文件中是一個字典的形式{name:[pwd,tel]},為啥會報錯 ?請指點

strip() key all urn pen nco nbsp cal rac

def register(name, pwd, tel):
    with open(userdate.txt, a, encoding=utf-8) as f:
        new = {}
        new[name] = [pwd,tel]
        f.write(\n + str(new))
        return True
def same(name):
    with open(userdate.txt, r, encoding=utf-8) as f:
        for i in f:
            for
k in eval(i): # 為什麽eval(i)沒有字典的方法keys() if name == k: return False return Truedef main(): print(1:註冊) choice = input(請選擇).strip() if choice == 1: name = input(輸入用戶名).strip() if same(name): pwd = input(輸入密碼).strip() tel
= input(輸入電話).strip() if register(name, pwd, tel): print(註冊成功) else: print(用戶名已被占用,重新輸入) main() ‘’‘ ———————————————————— 報錯的信息 Traceback (most recent call last): File "E:/py/666.py", line 54, in <module> main() File "E:/py/666.py
", line 35, in main if same(name): File "E:/py/666.py", line 12, in same for k in eval(i): File "<string>", line 1 ^ SyntaxError: unexpected EOF while parsing Process finished with exit code 1 ’‘’

做一個登陸的文件操作,存到文件中是一個字典的形式{name:[pwd,tel]},為啥會報錯 ?請指點