代码之家  ›  专栏  ›  技术社区  ›  lsr729

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

  •  0
  • lsr729  · 技术社区  · 2 年前

    我在jupyter笔记本上做了一个函数,结果手机被删除了。我想知道函数中的代码。我不能用 undo deleted cell 因为它很久以前就被删除了。该功能不会从笔记本内存中删除,因为我可以运行它。有没有办法让代码写入函数中?

    1 回复  |  直到 2 年前
        1
  •  1
  •   Sloxy    2 年前

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

    这篇文章提供了一种通过inspect库获取信息的方法: 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.