问题描述
PDB(和其他Python调试器)有一个简单的方法来查看任何当前变量的值,只需要输入它即可。但是,有时我使用不将其返回值存储在中间变量中的库。这是一个示例函数:
def do_stuff(* args,** kwds):
return f(* args,** kwds)
f,我如何看到返回值?我可以在下载它们之后重新编写一个库:
def do_stuff(* args,** kwds):
r = f(* args,** kwds)
return r
但似乎就像应该有更好的方法。
你可以查看一个隐藏的 __ return __
局部变量。
如果我忘记了这个确切的名称,我将通过以下方式进行探索:
(Pdb)sorted(locals()。keys())
['__return__','xyz',...]
编辑:我的相关的以后的答案与
PDB (and other Python debuggers) have a simple way of viewing the value of any current variable, just by typing it in. However, sometimes I work with libraries that don't store their return values in intermediate variables.
Here's an example function:
def do_stuff(*args, **kwds):
return f(*args, **kwds)
After I return from f, how do I see the return value? I could rewrite libraries after I download them to have an intermediate:
def do_stuff(*args, **kwds):
r = f(*args, **kwds)
return r
but it seems like there should be a better way.
You can look into a hidden __return__
local variable.
If I forget it's exact name, I explore it by:
(Pdb) sorted(locals().keys())
['__return__', 'xyz', ...]
EDIT: My related later answer with example for __return__
这篇关于在Python调试器中,如何看到函数的返回值,没有中间值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!