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

lsr*_*729 0 python jupyter-notebook

我在 jupyter 笔记本中做了一个函数,单元格被删除了。我想知道函数中的代码。我无法使用,undo deleted cell因为它很久以前就被删除了。该函数不会从笔记本内存中删除,因为我可以运行它。有没有办法让代码写在函数内部?

小智 6

如果您像您所说的那样内存中仍然有该函数的源代码,您可能仍然可以获得该函数的源代码。

这篇文章提供了一种尝试通过检查库获取它的方法: /sf/answers/29927341/

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.
Run Code Online (Sandbox Code Playgroud)