请考虑以下代码:
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()
的范围以保存到目前为止生成的结果?