Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I import from another ipython-notebook?

I'd like to import a func from another ipython-notebook. Say,

common_func.ipnb has def func_a()

When I create a new notebook, how can I access the func_a which is from another notebook but in the same folder and same ipython instance?

like image 329
shuaiyuancn Avatar asked Oct 24 '13 11:10

shuaiyuancn


People also ask

How do I transfer one notebook to another?

We recommend using Microsoft Edge on Windows 10, or any other modern browser in older versions of Windows. On the screen that opens, click Import. On your computer, navigate to the location of your notebook folder (see Step 1), click to select it, and then click Open to import it.


1 Answers

When you start ipython use the --script flag: For example

ipython notebook --script 

Then whenever you save your notebook "common_func.ipnb" it will also create a file entitled "common_func.py." You can import functions from that by using

from common_func import func_a 

If you change the common_func notebook, you may need to use

reload() 
like image 79
Erich Mueller Avatar answered Sep 20 '22 06:09

Erich Mueller