最近写个project遇到个大坑,就是在外部的py文件修改了类的属性
在jupyter notebook中重新运行了导入的语句,实际上是无效的
需要重新载入 reload()
原来的类
比如外部有个test.py 文件,里面有一个TestClass类
from test import TestClass
reload(Testclass)
最好的方法是在我们的jupyter notebook中自动载入
# for auto-reloading external modules
# see http://stackoverflow.com/questions/1907993/autoreload-of-modules-in-ipython
%load_ext autoreload
%autoreload 2
这样在test.py中的任何改动都会同步到jupyter notebook的内存中
网友评论