EOFError: Ran out of input
来源:互联网 发布:足迹美图软件 编辑:程序博客网 时间:2024/06/05 02:30
使用pickle.load(f)加载pickle文件时,报错:EOFError: Ran out of input.
可能原因:文件为空。
解决办法:加载非空文件。
其他解决办法:
1、加载前判断文件是否为空
import osscores = {} # scores is an empty dict alreadyif 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 {}
参考:Why do I get “Pickle - EOFError: Ran out of input” reading an empty file?
阅读全文
1 0
- EOFError: Ran out of input
- python遇到的困难:总是报错EOFError: Ran out of input
- Dynamic MMap ran out of room
- apt-get: Dynamic MMap ran out of room的解决方法
- Error: Ran out of space in ROM for simsun.ac3
- ubuntu 10.04 E: Dynamic MMap ran out of room 解决方案
- 数据库读取错误:ran out of memory retrieving query results
- apt error:E: Dynamic MMap ran out of room。如何解决?
- Linux下update错误 E: Dynamic MMap ran out of room. 解决方法
- [收藏]Linux下update错误 E: Dynamic MMap ran out of room. 解决方法
- Linux下update错误 E: Dynamic MMap ran out of room. 的解决方法
- Apache:Server ran out of threads to serve requests. Consider raising the ThreadsPerChild setting
- keil for stm32中出现的警告" integer operation result is out of ran"
- Server ran out of threads to serve requests. Consider raising the ThreadsPerChild setting的解决方法
- zlib error while attempting compression: "Ran out of output buffer for writing compressed bytes."
- zlib error while attempting compression: "Ran out of output buffer for writing compressed bytes."
- EOFError
- Dynamic MMap ran out of room. Please increase the size of APT::Cache-Limit. Current value: 25165824.
- mysql 删除重复数据
- 小猪浅谈Android屏幕适配
- 浮沉千古事?谁与问东流。
- Spring MVC之@RequestBody, @ResponseBody 详解
- IO中其他流--节点流
- EOFError: Ran out of input
- constexpr关键字
- 【scala 笔记(4)】 控制结构 -- 自定义控制结构
- 常用的几款抓包工具
- JSP中调用java类中的方法
- JVM调优总结 -Xms -Xmx -Xmn -Xss
- MyEclipse Servers视窗出现“Could not create the view: An unexpected exception was thrown”错误
- 监控和管理生产环境spring boot actuator
- Spring Data JPA进阶——Specifications和Querydsl