I have a project written in python comprising of many files. Is there a tool or method to convert all of it into a single notebook file?
I’m not aware of such a file. And if your .py
files have cross dependencies, i.e. if you have lorem.py
and in ipsum.py
you have
from . import lorem
your transformation from .py
files into notebooks will be more challenge.
And you can customize all sorts of wrangling with nbformat
if you’d like to get all the content into the notebook, which isn’t advised as you now have two projects to maintain. It is likely not a ‘one-click solution’. I have a lot of useful posts with nbformat-related code that may spark ideas here and here.
Another useful trick that is related to the imports suggested is that you can run the script Python code in the notebooks namespace using %run -i <lorem.py>
.
Along the lines of this endeavor, there is Jupytext that has a command to convert a script to a notebook. However, as your code spread out amongst a set, it won’t be that easy. (I’m mainly adding mention of this tool for the sake others who find this and have a simpler situation.)