title: How do I pickle a dictionary containing a module & class?
body: <p>I need to assign a module &amp; class to a dictionary key.  Then pickle that dictionary to file.  Then later, load the pkl file, then import &amp; instantiate the class, based on that dictionary key value.</p>
  
  <p>I've tried this:</p>
  
  <pre><code>import module_example
  from module_example import ClassExample
  
  dictionary = {'module': module_example, 'class': ClassExample)
  </code></pre>
  
  <p>Yet it won't store a reference to module_exmaple.py in the pkl file.</p>
  
  <p>I've tried a workaround of using a string instead of the module &amp; class name.  But that's going to lead to a mess if the module name gets refactored or location is changed down the road.</p>
  
  <p>Is there anyway do this directly?  Somehow store a reference to the module &amp; class in a dictionary, then later import &amp; instantiate based on that reference?</p>