mardi 18 décembre 2018

Trying to fix an error in code that is suppose to process data using the hash function in a random access file

I am following a book in learning how to process data in a random access file using the hash function. The problem is I don't think the code they have provided is completed. When I run the code as is, it first tells me that I have an indent problem then it says it says their is a name error CarRecord is not defined. I am guessing that I should add more to the code for it to work, maybe a class but my knowledge of working on this code is limited so before I start to make changes I will ask for your help.

import pickle                       # this library is required to create binary files

ThisCar = CarRecord()


CarFile = open('Cars.DAT','rb+')    #open this file for binary read and write
Address = hash(ThisCar.VehicleID)
CarFile.seek(Address)
pickle.dump(ThisCar, CarFile)       #write a whole record to the binary file

CarFile.close()

CarFile = open('Cars.DAT','rb')     #open file for binary read
Address = hash(VehicleID)
CarFile.seek(Address)
    ThisCar = pickle.load(CarFile)      #load record from file

CarFile.close()




Aucun commentaire:

Enregistrer un commentaire