title: cPickle: UnpicklingError: invalid load key, 'A'
body: <p>I have a pickle file which upon unpickling throws an <code>UnpicklingError: invalid load key, 'A'.</code> exception. The exception gets thrown regardless of whether I try to analyse it on the Ubuntu 14.04 machine on which the file was generated or on my Windows machine. It contains 26 data points and the exception gets thrown after data point 11. I suspect I must have somehow accidentally edited the file though I don't know when or how. I know there are several other discussions on this sort of error but so far I haven't found a post yet telling me if and how I could go about recovering the values after the faulty entry (I suspect one of the values is just irretrievably lost). Is there any way I could skip it and carry on unpickling the next one? Can one e.g. unpickle in the reverse direction, i.e. last element first? Then I could work backwards till I hit the faulty entry and thus get the other values. (I could regenerate the data but it would take a day or two so I would rather avoid having to do that if I can.)</p>
  
  <p>This is the code for pickling:</p>
  
  <pre><code>with open('hist_vs_years2.pkl', 'ab') as hist_pkl:
          pickle.dump(hist, hist_pkl, -1)
  </code></pre>
  
  <p>And this is the code for unpickling:</p>
  
  <pre><code>hist_vs_samples2 = []
  more_values = True
  
  with open('hist_vs_years2.pkl', 'rb') as hist_vs_samples_pkl:
      while more_values == True:
          try:
              hist_vs_samples2.append(pickle.load(hist_vs_samples_pkl))
          except EOFError:
              more_values = False
  </code></pre>
  
  <p>I should add that I am using cPickle. If I try to unpickle using pickle I get the following error:</p>
  
  <pre><code>  File "C:\Anaconda2\lib\pickle.py", line 1384, in load
      return Unpickler(file).load()
  
    File "C:\Anaconda2\lib\pickle.py", line 864, in load
      dispatch[key](self)
  
  KeyError: 'A'
  </code></pre>