title: Why doesn't `sys.modules.keys()` include name from `import...as`?
body: <p>Say I import a module as follows:</p>
  
  <pre><code>import os as OSMOD
  </code></pre>
  
  <p>and then wanted to find the working directory</p>
  
  <pre><code>OSMOD.getcwd()
  </code></pre>
  
  <p><code>OSMOD</code> is now a stand in for <code>os</code>, and using <code>os</code> won't work.  This is all dandy, and works for me. However, I noticed something a little odd.  If I import <code>os</code> as I do above, and then get a list of all imported modules, here's what happens:</p>
  
  <pre><code>&gt;&gt;&gt; import sys
  &gt;&gt;&gt; import os as OSMOD
  &gt;&gt;&gt; modList = sys.modules.keys()
  &gt;&gt;&gt; print "os" in modList
  True
  &gt;&gt;&gt; print "OSMOD" in modList
  False
  </code></pre>
  
  <p>This is not what I expected.  According to the docs <code>modules.keys() only lists the imported modules</code>.  To me, this means it should list <code>OSMOD</code>.  </p>
  
  <p>Why doesn't <code>sys.modules.keys()</code> contain <code>OSMOD</code> instead of <code>os</code>?</p>
  
  <p>Additionally, is there an equivalent list to <code>sys.modules.keys()</code> which would contain <code>OSMOD</code>?</p>
  
  <p><strong>EDIT:</strong> I guess the larger question here is the rationale.  If Python is going to keep <code>os</code> as the module, why delete the reference? (ie, why don't both <code>os.getcwd()</code> and <code>OSMOD.getcwd()</code> work?)</p>
  
  <p>Or, more simply put, why doesn't <code>import os as OSMOD</code> behave the same as <code>import os</code> followed by <code>OSMOD = os</code>?</p>