Nov-03-2021, 04:38 PM
I am facing the error: OSError: [Errno 22] Invalid argument when trying to dump an object record to the hashed address in a .dat binary file, any idea where I am going wrong?
import pickle # Creating the Record class CarRecord: def __init__(self): self.VehicleID="" self.Registration="" self.DateOfRegistration = None self.EngineSize = 0 self.PurchasePrice = 0.00 CarsArray=["" for i in range(2)] #Creating the array #Creating the binary file CarsFile=open("CarsRAND.dat", 'wb') #Assigning each array element to the class for i in range(2): CarsArray[i]= CarRecord() VehicleID=str(input("Enter Vehicle ID")) CarsArray[i].VehicleID=(VehicleID) print ("Vehicle ID:", i, CarsArray[i].VehicleID, " has been entered") #writing each record to the file for i in range(2): Address=hash(CarsArray[i].VehicleID) #Hashing address print("Address: ", str(i), Address) CarsFile.seek(Address) #Seeking hashed address pickle.dump(CarsArray[i],CarsFile) #Putting record in hashed address CarsFile.close # Reading record from hashed address. CarsFile=open("CarsRND.dat", 'rb') VehicleID=str(input("Enter Vehicle ID to Load")) Address=hash(VehicleID) CarsFile.seek(Address) Record = pickle.load(CarsFile) print(Record.VehicleID) CarsFile.close