Skip to main content

Jupyter: the easiest way to import code from another notebook

Yesterday I published a post about how to create a module in jupyter.

There is another way to quickly import the code from another notebook. Say you are working in your_notebook.ipynb and you need a Python class class Hello(): from another_notebook.ipynb. To import it you just need to do the following:

# in your_notebook.ipynb do
%run another_notebook.ipynb
hello = Hello()

Voila, with %run you access the code from the other notebook. Easy peasy.