title: How do I use hashing and pickle to save/load objects
body: <p>So I am following a guide in a book about working with random files and have the following code for saving some objects</p>
  
  <pre><code>import pickle
  from carRec import carRec
  
  cars = [carRec(1, "Ford", "Escort"), carRec(2, "Ford", "Focus"), carRec(3, "Ford", "Mustang")]
  
  #output to carsFile
  carFile = open("carsRand.dat", "wb")
  
  for i in range(0,3):
     address = hash(cars[i].vehicleID)
     carFile.seek(address)
     pickle.dump(cars[i], carFile)
  
  carFile.close()
  </code></pre>
  
  <p>And then for loading the data </p>
  
  <pre><code>import pickle
  from carRec import carRec
  
  carFile = open("cars.dat", "rb")
  cars = []
  counter = 1
  
  try:
      while True:
          location = hash(counter)
          carFile.seek(location)
          cars.append(pickle.load(carFile))
          counter += 1
  except EOFError:
      print("done")
  
  carFile.close()  
  </code></pre>
  
  <p>The problem is, when I try to reload the data I get the following error</p>
  
  <pre><code>_pickle.UnpicklingError: invalid load key, ''.
  </code></pre>
  
  <p>Having a quick look inside the dat file makes me think that the writing of the data isnt working properly. I believe that when using the hash and seek functions to identify where to write too/read from, you need to allow for the size of the record in bytes. If this is the case, how do I a) ensure all records are the same size and b) find out the size of a single record?</p>