kioku-space

As a personal memory space.

How to Save Jupyter Notebook's Code Execution History as a Python Script

In this article, I’ll introduce how to save the code execution history from Jupyter Notebook (JupyterLab) as a Python script.

First, I’ll go over the commonly used %history magic command and then share a custom function I’ve written.

Note
This method also works with Google Colaboratory.
  • By running the following command in a notebook cell, you can display the code execution history: