zoukankan      html  css  js  c++  java
  • EOFError: Ran out of input

    使用pickle.load(f)加载pickle文件时,报错:EOFError: Ran out of input. 
    可能原因:文件为空。 
    解决办法:加载非空文件。 
    其他解决办法: 

    1、加载前判断文件是否为空

    import os
    scores = {} # scores is an empty dict already
    if os.path.getsize(target) > 0:      
        with open(target, "rb") as f:
            unpickler = pickle.Unpickler(f)
            # if file is not empty scores will be equal
            # to the value unpickled
            scores = unpickler.load()

    2、捕获异常

    open(target, 'a').close()
    scores = {};
    try:
        with open(target, "rb") as file:
            unpickler = pickle.Unpickler(file);
            scores = unpickler.load();
            if not isinstance(scores, dict):
                scores = {};
    except EOFError:
        return {}

    --------------------- 本文来自 匠人_C 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/castle_cc/article/details/78193942?utm_source=copy 

  • 相关阅读:
    开课博客
    高级UI组件(二)
    《梦断代码》读后感(三)
    高级UI组件
    今日总结
    今日总结
    android中关于时间的控件
    单选按钮和复选框
    Android开发中按钮的语法
    布局管理器的嵌套
  • 原文地址:https://www.cnblogs.com/gabrielle/p/9758520.html
Copyright © 2011-2022 走看看