欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python使用pickle模塊報錯EOFError Ran out of input的解決方法

 更新時間:2018年08月16日 08:36:55   作者:不會寫python  
這篇文章主要介紹了Python使用pickle模塊報錯EOFError Ran out of input的解決方法,涉及Python異常捕獲操作處理相關(guān)使用技巧,需要的朋友可以參考下

本文實(shí)例講述了Python使用pickle模塊報錯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

更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python進(jìn)程與線程操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進(jìn)階經(jīng)典教程》及《Python文件與目錄操作技巧匯總

希望本文所述對大家Python程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評論