I made a function in the jupyter notebook and the cell got deleted. I want to know the code in the function. I cannot use undo deleted cell
because it got deleted a long time ago. The function is not deleted from the notebook memory as I can run it. Is there a way to get the code written inside the function?
Asked
Active
Viewed 243 times
0

lsr729
- 752
- 2
- 11
- 25
-
1try `%history`. it displays EVERY SINGLE command ever run in the notebook. – sean-7777 Apr 01 '22 at 00:40
1 Answers
5
You might still be able to get the source code of the function, if you still have it in memory like you say.
This post gives a way to try and get it through the inspect library: https://stackoverflow.com/a/427533/14486144
import inspect
lines = inspect.getsource(foo)
print(lines)
Try give that a shot, I tried it out in jupyter notebooks, although I wasn't exactly sure how to recreate your situation that you can't undo deleted cells. Try that out and see it if works.

Sloxy
- 82
- 10