I defined a hello world function in a file called 'functions.ipynb'. Now, I would like to import functions in another file by using "import functions". I am sure that they are in the same folder. However, it still shows that "ImportError: No module named functions". By the way, I am using jupyter notebook. Thanks a lot!
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You'll want to use the ipynb package/module importer. You'll need to install it: pip install ipynb
.
Create a Notebook named 'MyFunctions'. Add a simple function to it.
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
Then, create a second Ipython Notebook and import this function with:
from ipynb.fs.full.MyFunctions import factorial
Then you can use it as if it was in the same Ipython Notebook:
testing = factorial(5)
See the documentation for more details.