做一个登陆的文件操作,存到文件中是一个字典的形式{name:[pwd,tel]},为啥会报错 ?请指点
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 ’‘’