如何查看PDB中当前调试函数的返回值?

How to examine returned value of currently debugging function in PDB?

在检查 pdb 中的函数时,我可以 run the r(eturn) command,它将继续到函数 returns.

的位置

如何打印(或以其他方式检查)将成为 return 的值?

您可以使用变量 __return__(官方文档中没有参考,但您可以在源代码中找到一些实现细节:user_return and 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解释这个变量)