在检查 pdb
中的函数时,我可以 run the r(eturn)
command ,这将继续到函数返回的地方。
如何打印(或以其他方式检查)随后返回的值?
最佳答案
您可以使用变量__return__
(官方文档中没有引用,但您可以在源代码中找到一些实现细节: user_return 和 do_retval )
def do_it():
res = 'return me this'
import pdb;
pdb.set_trace()
return res
then = do_it()
> debug_it.py(7)do_it()
-> return res
(Pdb) r
--Return--
> debug_it.py(7)do_it()->'return me this'
-> return res
(Pdb) __return__
'return me this'
(另一个S.O post解释了这个变量)
关于python - 如何检查PDB中当前调试函数的返回值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51318006/