Libraries act differently depending on if they are installed or not
<p>I have a Python library I wrote which has been acting up on me. I have a set of variables which change the way the library works. In testing it all worked fine, but when I <code>python lib.py install</code> the variables have no effect on the library. I broke this down to the simplest example possible:</p>

<p>Library:</p>

<pre><code>    ##lib.py
    config="Original"

    def run():
        print config
</code></pre>

<p>Script:</p>

<pre><code>    import lib

    lib.config="New"
    lib.run()
    print lib.config
</code></pre>

<p>If you place the library in the same directory as the script and run it the output is:</p>

<pre><code>    New
    New
</code></pre>

<p>But if you install the library and then try the script using the library from the dist-packages the output is:</p>

<pre><code>    Original
    New
</code></pre>

<p>Could someone explain what is going on? I'm a bit confused and terribly interested in the happenings and reason. Additionally am I doing programatical configuration totally wrong?</p>

<p><strong>Edit</strong></p>

<p>It turns out the problem is the <strong>init</strong>.py file. It's basically like importing a library that just imports another library. When you import an installed module it looks at the folder <code>lib</code> and the file <strong>init</strong>.py. <strong>init</strong>.py is just a one liner <code>from lib import *</code>. It simply pretends to be the actual library, but that causes an odd problem if you use a global variable. A simulated example of what is essentially going on:</p>

<pre><code>##init.py
from lib import *
</code></pre>

<p>Script:</p>

<pre><code>import init

init.config = 'New'
init.run()
print init.config
</code></pre>

<p>Output:</p>

<pre><code>Original
New
</code></pre>

<p>The function run() looks for <code>config</code> in lib.py, but <code>print init.config</code> looks for it in init.py. Thanks for the help everyone. Fix is to change the way the module installs (no <strong>init</strong>.py). Eventually, I hope to remove all the global variables, but for the time being everything works perfect.</p>
