擅长:python、mysql、java
<p>有几种方法可以解决这个问题:</p>
<h3>一。使用<code>import MyPak.MyMod</code>而不是<code>from MyPak import MyMod</code></h3>
<p>然后你可以写:</p>
<pre><code>from importlib import reload # If on Python 3
import MyPak.MyMod
reload(MyPak.MyMod)
</code></pre>
<p>而且有效。</p>
<h3>2。使用<a href="http://ipython.readthedocs.io/en/stable/api/generated/IPython.lib.deepreload.html" rel="noreferrer">IPython.lib.deepreload</a></h3>
<pre><code>from MyPak import MyMod
from IPython.lib.deepreload import reload
reload(MyPak) # This should also reload all submodules
</code></pre>
<h3>三。使用<a href="http://ipython.readthedocs.io/en/stable/config/extensions/autoreload.html" rel="noreferrer">autoreload</a>魔法</h3>
<pre><code>%load_ext autoreload
%autoreload 2
import MyPak.MyMod # All changes to MyPak.MyMod will be loaded automatically
</code></pre>