title: Pickle/Unpickle more complicated objects
body: <p>I'm having a more complicated object which also contains some inheritances and so on. I'd like to be able to pickle/unpickle it and save it as file in my git. But it only works while it's still in the memory. When I'm reading it as a file I can't convert it back properly.</p>
  
  <p>As long as I'm just using it within my python (Django) application it's fine:</p>
  
  <pre><code>myPickle=pickle.dumps(reallyComplicatedObject, 0).decode()
  ...
  myObject = pickle.loads(myPickle.encode())
  </code></pre>
  
  <p>Now I'm saving it for further usage (I'm having to pretend it's a file as Django won't allow me to save a string as a file):</p>
  
  <pre><code>fs = FileSystemStorage()
  
  notAFile = io.StringIO(pickle.dumps(reallyComplicatedObject, 0).decode())
  filename = fs.save(filename, notAFile)
  return fs.url(filename)
  </code></pre>
  
  <p>This did as it was supposed to. I'm having a file that looks more or less binary to me
  Now the unpickle:</p>
  
  <pre><code>storage_class = get_storage_class(settings.STATICFILES_STORAGE)
  complicatedPickle = None
  
  with storage_class().open('TestFiles/Pickles/thatOneObject') as picklereads:
      complicatedPickle = picklereads.read()
  pick = pickle.loads(complicatedPickle)
  </code></pre>
  
  <p>When I output <code>complicatedPickle</code> I'm getting a long string that does look binary to me. Here I wonder already as I expected a String - but it is:</p>
  
  <pre><code>(Pdb) type(complicatedPickle)
  &lt;class 'bytes'&gt;
  </code></pre>
  
  <p><code>pick</code> is a String and encoding it just makes it binary again:</p>
  
  <pre><code>(Pdb) type(pick)
  &lt;class 'str'&gt;
  (Pdb) type(pick.encode())
  &lt;class 'bytes'&gt;
  </code></pre>
  
  <p>I've tried to use <code>ast</code> like in this solution: <a href="https://stackoverflow.com/a/52891113/2516892">https://stackoverflow.com/a/52891113/2516892</a></p>
  
  <pre><code>nopick = pickle.loads(ast.literal_eval(complicatedPickle))
  </code></pre>
  
  <p>But something is going wrong as this just outputs the object. I'm not having a <code>nopick</code> variable afterwards.</p>
  
  <p>The next solution on the same page is not helpful either:</p>
  
  <pre><code>(Pdb) unpick=pickle.loads(bytes(complicatedPickle))
  (Pdb) type(unpick)
  &lt;class 'str'&gt;
  (Pdb) unpick=pickle.loads(bytes(complicatedPickle, "latin1"))
  *** TypeError: encoding without a string argument
  (Pdb) unpick=pickle.load(bytes(complicatedPickle, "latin1"))
  *** TypeError: encoding without a string argument
  </code></pre>
  
  <p>I'm stuck now. Is there an error in my conversion already? Or how am I supposed to objectify it again? Or could the problem be Django-Related as I'm not using the regular <code>open</code>, but <code>storage_class</code>?</p>