查看Python函数的代码 [英] Viewing the code of a Python function
本文介绍了查看Python函数的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我在Python shell中工作,并且得到了函数f
.如何访问包含其源代码的字符串? (从外壳程序,而不是通过手动打开代码文件.)
Let's say I'm working in the Python shell and I'm given a function f
. How can I access the string containing its source code? (From the shell, not by manually opening the code file.)
即使是在其他函数中定义的lambda函数,我也希望这样做.
I want this to work even for lambda functions defined inside other functions.
推荐答案
检查. getsource
看来getsource无法获取lambda的源代码.
inspect.getsource
It looks getsource can't get lambda's source code.
这篇关于查看Python函数的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文