繁体   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)***

但它给了这个 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

使用 try except 跳过此特定错误:

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

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM