Globals across modules
<p>Wow, this seems so basic, but I can't get it to work. All I need to do is store a global dict which can be accessed and modified from other modules &amp; threads.</p>

<p>What's the "best practices" way of achieving this?</p>

<p>test.py</p>

<pre><code>import testmodule

class MyClassA():
    def __init__(self, id):
        self.id = id

if __name__ == '__main__':
    global classa_dict
    classa_dict = {}
    classa_dict[1] = MyClassA(1)
    classa_dict[2] = MyClassA(2)

    testing = testmodule.TestModule()
</code></pre>

<p>testmodule.py</p>

<pre><code>class TestModule():
    def __init__(self):
        global classa_dict
        print classa_dict[2]
</code></pre>

<p>output</p>

<pre><code>$ python test.py 
Traceback (most recent call last):
  File "test.py", line 13, in &lt;module&gt;
    testing = testmodule.TestModule()
  File "/path/to/project/testmodule.py", line 4, in __init__
    print classa_dict[2]
NameError: global name 'classa_dict' is not defined
</code></pre>
