在 Jupyter 中删除了一个函数的单元格

Deleted a cell of a function in Jupyter

我在 jupyter notebook 中创建了一个函数,单元格被删除了。我想知道函数中的代码。我不能使用 undo deleted cell 因为它很久以前就被删除了。该功能并没有从笔记本内存中删除,因为我可以 运行 它。有没有办法把代码写在函数里面?

如果你像你说的那样还在内存中,你可能仍然可以获得函数的源代码。

这个post提供了一种尝试通过检查库获取它的方法:

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.