python遇到的困难:总是报错EOFError: Ran out of input

遇到了 EOFError:Ran out of input 不到为什么这样,最后用捕获异常的办法解决掉了,暂时对程序本身没有啥影响,代码如下:
# coding=utf-8
import pickle
def usr_date():
    try:
        with open('usr_date.pkl','rb') as f:
            return pickle.load(f)
    except EOFError: #捕获异常EOFError 后返回None
        return None

def update_usr(usr_dic):
    with open('usr_date.pkl','wb') as f:
         pickle.dump(usr_dic,f)


def register():
    '注册'
    usr_dic = {}
    usr_name = input('请输入用户名')
    open_date = usr_date() if usr_date() else {}
    if usr_name in open_date.keys():
        print('用户已存在,请登录')
        return False
    usr_password = input('请输入你的密码:')
    usr_dic[usr_name] = usr_password
    update_usr(usr_dic)
    return print('注册成功')

def Sign_in():
    '登录'
    pass

def login_index():
    while True:
        usr = input('1.注册 2.登录 0.退出')
        if usr == '1':
            register()
        elif usr =='2':
            Sign_in()
        else:
            break
最后感谢 点击打开链接的这篇文章,非常感谢。

你可能感兴趣的:(困难,python遇到的困难)