아래의 코드를 실행하면 "EOFError : 입력이 끊어졌습니다"라는 오류 메시지가 표시됩니다. 무엇을 의미합니까 ?? 어떻게 수정 될 수 있습니까 ?? 화면에 레코드 정보를 출력하는 방법에 대해 설명합니다.EOFError : 입력 범위를 벗어난 경우
는 는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()
을 접수에 때 'while true '루프는 데이터의 끝에 도달했을 때 데이터에서 다른 프로세스를 수행하려고 시도하기 때문에 – WhatsThePoint
직접'Car'리스트를 pickle/unpickle하려고 시도합니다. –
어떻게 그럴 수 있습니까? – Chris