以下のコードを実行すると、「EOFError:入力がなくなる」というエラーメッセージが表示されます 何を意味していますか?どのように修正することができますか?レコードの詳細を画面に出力する方法について説明します。EOFError:入力が無効になりました
あなたがこれまであなたwhile
ループを変更することができます
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()
をrecievesます'while true 'ループは、データの終わりに達したときに、それがないデータに対して別のプロセスを実行しようとしているためです – WhatsThePoint
' Car'リストを直接pickle/unpickleしようとします –
それを行う方法? – Chris