代码之家  ›  专栏  ›  技术社区  ›  Chris W.

如何检查pdb中当前调试函数的返回值?

  •  2
  • Chris W.  · 技术社区  · 7 年前

    在中检查函数时 pdb ,我可以 run the r(eturn) command ,它将继续到函数返回的位置。

    如何打印(或以其他方式检查)将返回的值?

    1 回复  |  直到 7 年前
        1
  •  2
  •   PRMoureu    7 年前

    您可以使用变量 __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 解释此变量)