Does Python import instantiate a mystery class?
<p>I thought about this for a while and can't think of a better title, sorry.</p>

<p>I'm new'ish to Python, and (like many other's it seems) I just can't get my head around <code>import</code>.</p>

<p>I think I understand 'modules' and 'packages', classes and attributes and all that.  It's one specific behavior I need clarified.</p>

<p>Say I have a file, foo.py.  It has one line it:</p>

<pre><code>x = 1
</code></pre>

<p>If, in another file, I `import foo", I can reference x.  And, wonderfully, in another file I can import foo and now those two files can share x.  Leaving classes out of the discussion for simplicity, I believe this is the pythonic way to share attributes between files.</p>

<p>Here's the question: Is is fair to say, when I <code>import foo</code>, that foo.py itself is, (for lack of a better metaphor), secretly <em>instantiated</em> by the interpreter?  </p>

<p>I realize if I define a class in a module, it follow traditional rules and only become instantiated if I explicitly do so.  But, the python interpreter (via the <code>import</code> statement) instantiating an instance of my module in the global namespace is the only way to explain the attribute sharing behavior.</p>

<p>Is this true?  Semi-true?  Or am I wandering with the Sleestaks in the Land of the Lost?</p>
