Including a notebook in another notebook in IPython?

点点圈 提交于 2019-12-30 05:06:05

问题


I have a notebook which I intend to use as a library for other notebooks. It has some functions that can ready certain types of files etc.

How can I include that notebook in a new notebook that should be able to use the functions in the library notebook?


回答1:


googling for notebook import hook yield some examples. This is still experimental, but you are welcomed to improved it. I would suggest also using the --script flag that save an importable .py file every time you save the notebook.




回答2:


You can just enter %run 'NotebookA.ipynb' in Notebook B and you should be good to go!




回答3:


With import_ipynb library using A.ipynb from B.ipynb is as simple as writing

import import_ipynb
import A

in B.ipynb.

Actually this library is just one file I've taken from the official jupyter howto and wrapped into a package installable via

pip install import-ipynb

It's also possible to write from A import foo, from A import * and so on.



来源:https://stackoverflow.com/questions/19082397/including-a-notebook-in-another-notebook-in-ipython

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!