如何查看/打印保存在变量中但已删除代码的函数?

How to see/print a function saved in a variable but with deleted code?

提问人:Mashhood Ahmad 提问时间:10/17/2020 最后编辑:martineauMashhood Ahmad 更新时间:10/17/2020 访问量:262

问:

我正在编写一个脚本,不久前不小心删除了一个函数的代码(所以无法撤消),但该函数保存在内存中。

print(diff)

#output
<function diff at 0x7f48f238a670>

有没有办法打印这个函数的代码?

Python 函数

评论

1赞 mkrieger1 10/17/2020
这回答了你的问题吗?如何获取 Python 函数的源代码?
0赞 Murtaza Haji 10/17/2020
这回答了你的问题吗?如何让 Python 写下内存中函数的代码?
3赞 user2357112 10/17/2020
@MurtazaHaji:这依赖于仍然存在的源文件。
0赞 martineau 10/17/2020
如果源代码消失了,则不会。
1赞 awesoon 10/18/2020
我将首先使用 dis 检索字节码,然后尝试使用 uncompyle6 或类似工具转换回 python,具体取决于实际的 python 版本。

答: 暂无答案