title: module importing itself
body: <p>I'm trying to import a module from an application-specific terminal (Maya in this case, but eventually others). I've downloaded a project off git, and I have a structure like so:</p>
  
  <pre><code>modulename
      submodule
          __init.py__
          subsubmodule
          ...
      submodule
      ...
      __init.py__
      modulename.py
  </code></pre>
  
  <p>Then in my execution shell, I'm trying to import the module to use on the shell, so I have:</p>
  
  <pre><code>import sys,os
  modulepath = 'C:/path/to/module'
  sys.path.append(modulepath)
  import modulename
  </code></pre>
  
  <p>If the modulename.py being imported is blank, everything is fine.
  The first two lines of the module are, however, the module trying to import itself (I don't really know why, seeing as this is someone elses project, but it seems to be important to the structure)</p>
  
  <pre><code>import sys,os
  import modulename from modulename as mod
  </code></pre>
  
  <p>This gets the error:</p>
  
  <pre><code># Error: ImportError: cannot import name modulename# 
  </code></pre>
  
  <p>And nothing else can proceed.</p>
  
  <p>Ultimately I'm wondering why a module can't import itself, and/or how to get around that problem?</p>
  
  <p>I have read that a module thinks of itself as being named <strong>main</strong> so that relative imports don't work, in which case I would expect</p>
  
  <pre><code>import __main__ as mod
  </code></pre>
  
  <p>to work in its stead, which also does not, with error:</p>
  
  <pre><code># Error: ImportError: Cannot re-init internal module __main__ #
  </code></pre>
  
  <p>Which makes total sense.</p>
  
  <p>[The question is, how can I import a module from within itself?]</p>