擅长:python、mysql、java
<p>函数可以将某些内容返回到调用它们的位置。它叫做它们的返回值:p</p>
<pre><code>def import_something():
# decide what to import
# ...
mod = __import__( something )
return mod
my_module = import_something()
my_module.do_stuff()
</code></pre>
<p>风格不错,没有麻烦。在</p>
<p>关于您的更新,我认为向您添加这样的内容<code>__init__.py</code>可以满足您的需要:</p>
^{pr2}$
<p>其他地方:</p>
<pre><code>import crunchers
crunchers.installed # all names
crunchers.cruncherA # actual module object, but you can't use it since you don't know the name when you write the code
# turns out the be pretty much the same as the first solution :p
mycruncher = getattr(crunchers, crunchers.installed[0])
</code></pre>