Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split jupyter notebook into several files

I am currently creating many tables in python and most of the cells need their own SQL query. I am ending up with a long list of SQL querys. Ideally I would put the table creation of each table in its own file and load the files from a main notebook.

Is there a way to run sub-notebooks (containing the tables) from one main notebook? Mathematica has the EvaulateNotebook[] function which does exactly this. For python I found the nbconvert package which seems to come close to what I need. However, nbconvert seems to run in its own kernel. I would need the sub-notebook to have access to all variables in the main-notebook and subesquently the main-notebook to have acess to the variables in the sub-notebook.

In the end I would like to have the convenience of the notebooks in terms of editing, while not having to scroll through each and every table if I only need to change one table. So I am a bit reluctant to build a standard python package which I import, but would rather have a way to run a sub-ipynb in a way as if the cells where in the main-notebook.

like image 746
Coolkau Avatar asked Dec 17 '25 13:12

Coolkau


1 Answers

I don't believe this is currently possible in Jupyter to have "child" notebooks in the same way you can with knitr.

Fernando Perez wrote a script to merge together multiple notebooks which may be helpful in your case to avoid having to scroll through a lot of text.

It looks like this may also eventually be incorporated into the main nbconvert codebase (see issue here).

like image 97
Keith Hughitt Avatar answered Dec 19 '25 06:12

Keith Hughitt