title: When using Python classes as program configuration structures (which includes inherited class attributes), a good way to save/restore?
body: <p>Let's say I have a (simplified) class as below. I am using it for a program configuration (hyperparameters).</p>
  
  <pre><code># config.py
  class Config(object):      # default configuration
      GPU_COUNT = 1
      IMAGES_PER_GPU = 2
      MAP = {1:2, 2:3}
  
      def display(self):
          pass
  
  # experiment1.py
  from config import Config as Default
  class Config(Default):     # some over-written configuration
      GPU_COUNT = 2
      NAME='2'            
  
  # run.py
  from experiment1 import Config
  cfg = Config()
  ...
  cfg.NAME = 'ABC'            # possible runtime over-writing
  
  # Now I would like to save `cfg` at this moment
  </code></pre>
  
  <p>I'd like to save this configuration and restore later. The member functions must be out of concern when restoring.</p>
  
  <p><strong>1. When I tried pickle:</strong></p>
  
  <pre><code>import pickle
  with open('cfg.pk', 'rb') as f: cfg = pickle.load(f)
  
  ##--&gt; AttributeError: Can't get attribute 'Config' on &lt;module '__main__'&gt;
  </code></pre>
  
  <p>I saw a solution using <code>class_def</code> of <code>Config</code>, but I wish I can restore the configuration without knowing the class definition (eg, export to dict and save as JSON)</p>
  
  <p><strong>2. I tried to convert class to dict</strong> (so that I can export as JSON)</p>
  
  <pre><code>cfg.__dict__     # {'NAME': 'ABC'}
  vars(cfg)        # {'NAME': 'ABC'} 
  </code></pre>
  
  <p>In both cases, it was difficult to access attributes. Is it possible?</p>