zoukankan      html  css  js  c++  java
  • 做一个登陆的文件操作,存到文件中是一个字典的形式{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('
    ' + 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
    ’‘’
  • 相关阅读:
    POJ 1320 Street Numbers(佩尔方程)
    hdu 3292 No more tricks, Mr Nanguo
    佩尔方程
    hdu 4825 xor sum(字典树+位运算)
    Xor Sum 2(位运算)
    数串
    EJS
    JQuery性能优化
    常用正则
    JavaScript prototype继承中的问题
  • 原文地址:https://www.cnblogs.com/xusuns/p/8412625.html
Copyright © 2011-2022 走看看