简体   繁体   English

为什么我在 python 中运行此代码时出现输入错误?

[英]Why i m getting Ran out of input Error when i m running this code in python?

import pickle
class salesrecord:
    def __init__(self):
        self.bedsheets = 0
        self.blankets = 0
        self.pillows = 0
        self.covers = 0
        self.address = 0
one_day_record = salesrecord()
one_week_record = [one_day_record for i in range(7)] # Make 1D Array to store records
binary_file = open("Record.DAT", "wb")  # open file to save records
for i in range(7): # Save each record in file
    pickle.dump(one_week_record[i], binary_file) 
print("File Created")
binary_file.close() # File Created
binary_file = open("Record.DAT", "rb") # File again open for reading

one_week_record = []
while True: # Read until EOF
    one_week_record.append(pickle.load(binary_file))
binary_file.close()
print(one_week_record)***

But it is giving this output但它给了这个 output

Traceback (most recent call last):
  File "E:/Python/New/New.py", line 27, in <module>
      one_week_record.append(pickle.load(binary_file))
EOFError: Ran out of input

Use try except to skip this particular error:使用 try except 跳过此特定错误:

while True:
    try:
        one_week_record.append(pickle.load(binary_file))
    except EOFError:
        break

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我不知道为什么我会在 Python 中收到此错误 - I dont know why I'm getting this error in Python 运行基于 Selenium 的代码时出现名称错误 - I'm getting a name error when running Selenium-based code 为什么在 python 中写入文本文件时出现错误? - Why I'm getting error while writing into text file in python? 为什么我会收到此错误? python-weka-包装器 3 - Why i'm getting this error? python-weka-wrapper 3 当我尝试通过 python 脚本执行 shell 命令时出现错误“找不到模块” - I'm getting an error “module not found ” when I'm trying to execute shell commands through a python script 不知道为什么我得到这个属性错误 - Not sure why I'm getting this attribute error 我收到类型错误,但不确定为什么吗? - I'm getting a type error but not sure why? 为什么我收到这个错误? 机器人应该分配 ID=899279907216031744 的角色,当我提供这种类型的输入时出现错误 - Why I'm getting this error? The bot is supposed to assign the role with ID=899279907216031744 , I'm getting error when I'm giving this type of Inputs 我在Python 3中遇到SyntaxError - I'm getting a SyntaxError in Python 3 我在 Python 中收到 AttributeError - I'm getting AttributeError in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM