EOFError: Ran out of input

When I run the code below I get this error message “EOFError: Ran out of input” what does it mean?? How it can be corrected?? and how to output the records details on the screen.

import pickle # this library is required to create binary files
class CarRecord:
    def __init__(self):
      self.VehicleID = " "          
      self.Registration = " "
      self.DateOfRegistration = " "
      self.EngineSize = 0           
      self.PurchasePrice = 0.00

ThisCar = CarRecord()
Car = [ThisCar for i in range(2)] # list of 2 car records

Car[0].VehicleID = "CD333"
Car[0].Registration = "17888"
Car[0].DateOfRegistration = "18/2/2017"
Car[0].EngineSize = 2500
Car[0].PurchasePrice = 22000.00

Car[1].VehicleID = "AB123"
Car[1].Registration = "16988"
Car[1].DateOfRegistration = "19/2/2017"
Car[1].EngineSize = 2500
Car[1].PurchasePrice = 20000.00

CarFile = open ('Cars.TXT', 'wb' ) # open file for binary write
for j in range (2): # loop for each array element
    pickle.dump (Car[j], CarFile) # write a whole record to the binary file
CarFile.close() # close file

CarFile = open ('Cars.TXT','rb') # open file for binary read
Car = [] # start with empty list
while True: #check for end of file
    Car.append(pickle.load(CarFile)) # append record from file to end of list
CarFile.close()

Leave a Comment