首页 > 解决方案 > 如何在 jupyter 中正确导入 py 文件并访问在此 py 文件中也导入的模块?

问题描述

我对 python 并不陌生,但不知何故我从未使用过这种机制:例如:我有一个 python 文件test.py,它看起来像:

'''test.py'''
from anothertest import anothertestfunc
def test(a):
   return a

如果我将该文件导入 jupyter 笔记本中,例如:

[1] import test

我怎样才能在jupyter中加载另一个testfunc模块,所以我可以像使用它一样

[1] import test
[2] anothertestfunc

现在我只得到对我来说完全有意义的错误消息“anotherfunc is not defined”。但是如何正确导入一个py文件,里面也导入了模块,所以我在jupyter中加载后使用这些模块?

提前致谢

标签: pythonimportmodulejupyter-notebookjupyter

解决方案


推荐阅读