Python module can't see class file that was already loaded
<p>I'm developing an interactive modeling platform called QREDIS.  It is composed of a set of interrelated modules, which get imported by a setup script and provide a set of model research functionality to the user.</p>

<p>As part of the setup, I load a class <code>QMod_Template</code> using</p>

<pre><code>exec(open('QMod_Template.py').read())
</code></pre>

<p>This class is a base class for user-definable models; i.e. the user can define and save a new model <code>QMod_MyModel(QMod_Template)</code>.  All this works perfectly.  I don't want to force the user to later reload his model with <code>exec(open('QMod_MyModel.py').read())</code>, so I've created a function <code>LoadModel</code> in model <code>QREDIS_Model</code> which will load a specified model class file (basically a wrapper for the <code>exec</code> code).  </p>

<p>When I execute this function, I get an error <code>NameError: name 'QMod_Template' is not defined</code>.  To summarize</p>

<p>First I load a class from a file:</p>

<pre><code>exec(open('QMod_Template.py').read())
</code></pre>

<p>Then I import a module</p>

<pre><code>import QREDIS_Model as QM
</code></pre>

<p>Then I try to load another model class file</p>

<pre><code>QM.LoadModel('QMod_MyModel.py')
</code></pre>

<p>and get the NameError.</p>

<p>Essentially, <code>QREDIS_Model.LoadModel</code> needs to be able to access the already loaded <code>QMod_Template</code> class, but can't.  I have tried declaring QMod_Template as global in both the module and function, but no luck.</p>

<p>This should be a simple fix I think.  What am I missing?  I hope this extended question makes my issue much more clear.</p>
