<p>没有,如果模块已经导入,则不会再次加载。</p>
<p>您只需获得对已导入模块的引用(它将来自<code>sys.modules</code>)。</p>
<p>要获取已导入的模块的列表,您可以查找<code>sys.modules.keys()</code>(注意<code>urllib</code>这里导入了一批其他模块):</p>
<pre><code>>>> import sys
>>> print len(sys.modules.keys())
44
>>> print sys.modules.keys()
['copy_reg', 'sre_compile', '_sre', 'encodings', 'site', '__builtin__', 'sysconfig', '__main__', 'encodings.encodings', 'abc', 'posixpath', '_weakrefset', 'errno', 'encodings.codecs', 'sre_constants', 're', '_abcoll', 'types', '_codecs', 'encodings.__builtin__', '_warnings', 'genericpath', 'stat', 'zipimport', '_sysconfigdata', 'warnings', 'UserDict', 'encodings.utf_8', 'sys', 'virtualenvwrapper', '_osx_support', 'codecs', 'readline', 'os.path', 'sitecustomize', 'signal', 'traceback', 'linecache', 'posix', 'encodings.aliases', 'exceptions', 'sre_parse', 'os', '_weakref']
>>> import urllib
>>> print len(sys.modules.keys())
70
>>> print sys.modules.keys()
['cStringIO', 'heapq', 'base64', 'copy_reg', 'sre_compile', '_collections', '_sre', 'functools', 'encodings', 'site', '__builtin__', 'sysconfig', 'thread', '_ssl', '__main__', 'operator', 'encodings.encodings', '_heapq', 'abc', 'posixpath', '_weakrefset', 'errno', '_socket', 'binascii', 'encodings.codecs', 'urllib', 'sre_constants', 're', '_abcoll', 'collections', 'types', '_codecs', 'encodings.__builtin__', '_struct', '_warnings', '_scproxy', 'genericpath', 'stat', 'zipimport', '_sysconfigdata', 'string', 'warnings', 'UserDict', 'struct', 'encodings.utf_8', 'textwrap', 'sys', 'ssl', 'virtualenvwrapper', '_osx_support', 'codecs', 'readline', 'os.path', 'strop', '_functools', 'sitecustomize', 'socket', 'keyword', 'signal', 'traceback', 'urlparse', 'linecache', 'itertools', 'posix', 'encodings.aliases', 'time', 'exceptions', 'sre_parse', 'os', '_weakref']
>>> import urllib #again!
>>> print len(sys.modules.keys()) #has not loaded any additional modules
70
</code></pre>
<p>让我们来试一试:</p>
<pre><code>import sys
>>> sys.modules["foo"] = "bar" # Let's pretend we imported a module named "foo", which is a string.
>>> print __import__("foo")
bar # Not a module, that's my string!
</code></pre>
<p>如您所见,如果在<code>sys.modules</code>中找到一个模块,您将只获得对它的新引用。就这样。</p>
<hr/>
<p>请注意,这意味着<strong>模块的设计应确保在导入时不会产生副作用(例如打印内容)。</p>
<p>在交互会话之外重新加载模块通常也不是一个很好的实践(尽管它有自己的用例),其他的答案将详细说明如何做到这一点。</p>