title: Why does "import module" and then "from package import module" load the module again?
body: <p>I have a package in my PYTHONPATH that looks something like this:</p>
  
  <pre><code>package/
      __init__.py
      module.py
          print 'Loading module'
  </code></pre>
  
  <p>If I'm running Python from the <code>package/</code> directory (or writing another module in this directory) and type</p>
  
  <pre><code>import module
  </code></pre>
  
  <p>it loads module.py and prints out "Loading module" as expected. However, if I then type</p>
  
  <pre><code>from package import module
  </code></pre>
  
  <p>it loads module.py and prints "Loading module" <em>again</em>, which I don't expect. What's the rationale for this?</p>
  
  <p>Note: I think I understand technically why Python is doing this, because the sys.modules key for <code>import module</code> is just <code>"module"</code>, but for <code>from package import module</code> it's <code>"package.module"</code>. So I guess what I want to know is why the key is different here -- why isn't the file's path name used as the key so that Python does what one expects here?</p>