Jupyter Lab and notebook history callback (recover cell’s)— Quick Tip

Matjaž Hozjan
Sep 23, 2022

--

Probably any of us deleted a cell in Jupyter and wanted to recall it. Sometimes simple Edit/Undo works and there are times that this is not enough.

Photo by Lee Campbell on Unsplash

In the case that we changed some variables and deleted the whole cell after it and continued to work further, the Undo function for me is not an option as in this case you would redone everything to that point change was made.

Jupyter history callback

In the above picture I created a dummy_variable and changed it from 3 to 5. Then the 1st cell was deleted. To recall 10 last cells, the simple _ih[-10:] function needs to be called in a loop.

# look back what was dummy_variable at start

for history in _ih[-10:]:
print(history)

History recall in Jupyter Lab or notebook

Thank you for reading this short tip and trick and consider subscribing.

Thanks!

--

--

Matjaž Hozjan
Matjaž Hozjan

Written by Matjaž Hozjan

FX, stock trader and full time DataScientist at SportRadar AG

No responses yet