title: Python Class Inheritance : dict how to pickle(save, load)
body: <p>I'm playing around with class inheritances and I'm stuck on how to pickle data in the class dictionary.</p>
  
  <p>If dump only the dictionary part of self, when I load the dictionary back to self, self takes on a dict type instead of a class. But if I pickle the whole class then I get an error.</p>
  
  <h3>Error</h3>
  
  <pre><code>pickle.PicklingError: Can't pickle &lt;class 'main.model'&gt;: it's not the same object as main.model 
  </code></pre>
  
  <h3>Code</h3>
  
  <pre><code>import os, pickle
  
  class model(dict):
      def __init__( self ):
          pass
  
      def add( self, id, val ): 
          self[id] = val
  
      def delete( self, id ):   
          del self[id]
  
      def save( self ): 
          print type(self)
          pickle.dump( dict(self), open( "model.dict", "wb" ) )
  
      def load( self ): 
          print 'Before upacking model.dic, self ==',type(self)
          self = pickle.load( open( "model.dict", "rb" ) ) 
          print 'After upacking model.dic, self ==',type(self)
  
  if __name__ == '__main__':
      model = model()
      #uncomment after first run
      #model.load()
  
      #comment after first run
      model.add( 'South Park', 'Comedy Central' )
      model.save()
  </code></pre>