Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a Jupyter notebook from another notebook

I wonder if it is possible to run a *.ipynb file from another *.ipynb file and get a returned value. I know that we can run like this:

%run ./called_notebook.ipynb 

the called_notebook contains:

def foo():     print(1)     return 2 foo() 

But it only prints "1" without giving me the opportunity to handle the returned value. Is it even possible ? Does the following kind of code even exist :

a = %run ./called_notebook.ipynb 

?

Thanks !

like image 328
Valentin Fabianski Avatar asked Apr 13 '18 12:04

Valentin Fabianski


People also ask

How do you trigger one notebook from another notebook?

The %run command allows you to include another notebook within a notebook. You can use %run to modularize your code, for example by putting supporting functions in a separate notebook. You can also use it to concatenate notebooks that implement the steps in an analysis.

Can I access Jupyter notebook from another computer?

you can run jupyter notebook --no-browser --ip="<remote server ip>" on your remote machine terminal. And access notebooks using http://:8888/?token=<> from your browser on local machine.

Can I run two Jupyter notebooks at the same time?

Multiple notebooks and kernels In jupyter Lab, you can have multiple notebooks open at the same time and in the same browser window. Also, you can arrange your notebooks as you like which gives more flexibility.


1 Answers

I'd suggest running the foo function from the new notebook. In other words:

%run ./called_notebook.ipynb foo() 

In my opinion, this is best practices for using the %run magic command. Store your high level APIs in a separate notebook (such as foo), but keep your function calls visible in the master notebook.

like image 81
Matt Avatar answered Oct 03 '22 12:10

Matt