我是一个Jupyter Lab笔记本的用户,尝试修改代码并在Jupyter Notebook中重新加载它,而无需重新加载内核即可使用修改后的代码。我正在使用Python 3.5.5,并运行以下代码:
(在test.py文件中)
(在test.py文件中)
def myTest():
print('hello')
(在jupyter中)
from test import myTest
import importlib
importlib.reload(test)
myTest()
在我的jupyter lab笔记本中运行代码时,我得到了一个NameError错误,提示name 'test' is not defined
。通过在stackoverflow上搜索,我发现这种错误唯一的参考是使用旧版本的Python时会出现问题。但我正在使用的importlib.reload()
似乎是正确的。
test
?myTest
似乎已经被定义了。 - ChootsMagootsfrom test import myTest
。 - Jean-François Fabre