在使用Jupyter Notebook进行数据分析时,有时需要从本地py文件中导入函数。
这里出现的问题是,当目前的kernel还在运行中,如果对py文件中的函数名进行修改,并在jupyter中修改导入的函数名,则会出现无法导入的问题。这时必须将当前kernel shutdown,重新开始才能导入
----------------------------
从下面这个github中发现了解决问题的办法,
https://gist.github.com/deehzee/86ad60d3d2e375013ec710234f88968c
只要在notebook中添加如下内容即可:
# for auto-reloading external modules
# see http://stackoverflow.com/questions/1907993/autoreload-of-modules-in-ipython
%load_ext autoreload
%autoreload 2
之后就算不重新执行from ... import ... 也能重新导入函数