0

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?

lsr729
  • 752
  • 2
  • 11
  • 25

1 Answers1

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