Copy/pasting parts of a notebook into another one is a use case for Jupytext. Jupytext can export (the inputs) of your notebooks as .py
or .md
files. Execute either
jupytext --set-formats ipynb,py --sync *.ipynb
or
jupytext --set-formats ipynb,md --sync *.ipynb
Then edit the text files, move the desired inputs from one file to the other, and update the corresponding .ipynb
files with
jupytext --sync *.ipynb
Please note that only the outputs for which the inputs were unchanged are preserved in this operation.
Jupytext is also available as a plugin for Jupyter. In that context, you don't need to use the command line. You can pair your notebook to the desired text file using the File/Jupytext menu (Jupyter Notebook) or the Jupytext commands (Jupyter Lab). And you just have to refresh your paired notebook in the browser to get the latest edits on the paired text file.