ipython 事后调试:外部函数的作用域
ipython post-mortem debugging: scope of outer function
考虑以下代码:
def inner(a):
if a == 75:
raise RuntimeError()
return a**2
def outer():
results = []
for a in range(100):
results.append(inner(a))
return results
outer()
在 IPython 中,引发异常后,%debug
行魔法在 inner()
:
范围内打开 python 调试器
In [4]: %debug
> <ipython-input-3-eff43b15b2ef>(3)inner()
2 if a == 75:
----> 3 raise RuntimeError()
4 return a**2
ipdb> a
a = 75
ipdb> results
*** NameError: name 'results' is not defined
如何告诉 (i)pdb 进入 outer()
的范围以保存到目前为止生成的结果?
我认为你不能直接这样做。但是,一旦进入调试器,您可以轻松地键入 u
(向上)将当前帧向上移动一级并进入 outer
函数。有关命令的更多信息,请参阅 here。
考虑以下代码:
def inner(a):
if a == 75:
raise RuntimeError()
return a**2
def outer():
results = []
for a in range(100):
results.append(inner(a))
return results
outer()
在 IPython 中,引发异常后,%debug
行魔法在 inner()
:
In [4]: %debug
> <ipython-input-3-eff43b15b2ef>(3)inner()
2 if a == 75:
----> 3 raise RuntimeError()
4 return a**2
ipdb> a
a = 75
ipdb> results
*** NameError: name 'results' is not defined
如何告诉 (i)pdb 进入 outer()
的范围以保存到目前为止生成的结果?
我认为你不能直接这样做。但是,一旦进入调试器,您可以轻松地键入 u
(向上)将当前帧向上移动一级并进入 outer
函数。有关命令的更多信息,请参阅 here。