ZeroDivisionErrorTraceback (most recent call last)
<ipython-input-2-b2e110f6fc8f> in <module>()----> 1func2(1)<ipython-input-1-d849e34d61fb> in func2(x) 5 a = x
6 b = x -1----> 7return func1(a, b)<ipython-input-1-d849e34d61fb> in func1(a, b) 1def func1(a, b):----> 2return a / b
3 4def func2(x): 5 a = x
ZeroDivisionError: integer division or modulo by zero
Traceback (most recent call last):
File "<ipython-input-4-b2e110f6fc8f>", line 1, in <module>
func2(1)
File "<ipython-input-1-d849e34d61fb>", line 7, in func2
return func1(a, b)
File "<ipython-input-1-d849e34d61fb>", line 2, in func1 return a / bZeroDivisionError: integer division or modulo by zero
ZeroDivisionErrorTraceback (most recent call last)
<ipython-input-6-b2e110f6fc8f> in <module>()----> 1func2(1)globalfunc2= <function func2 at 0x7fa890d9b410><ipython-input-1-d849e34d61fb> in func2(x=1) 5 a = x
6 b = x -1----> 7return func1(a, b)globalfunc1= <function func1 at 0x7fa890d9b398>a= 1b= 0<ipython-input-1-d849e34d61fb> in func1(a=1, b=0) 1def func1(a, b):----> 2return a / b
a= 1b= 0 3 4def func2(x): 5 a = x
ZeroDivisionError: integer division or modulo by zero
> <ipython-input-1-d849e34d61fb>(2)func1() 1 def func1(a, b):----> 2 return a / b
3 4 def func2(x): 5 a = x
ipdb> a
1
ipdb> b
0
ipdb> quit
同时,在调试模式下,我们也可以通过输入“up”来对外层函数进行调试,查看其中的变量情况。
In [8]:
%debug
> <ipython-input-1-d849e34d61fb>(2)func1() 1 def func1(a, b):----> 2 return a / b
3 4 def func2(x): 5 a = x
ipdb> up
> <ipython-input-1-d849e34d61fb>(7)func2() 3 4 def func2(x): 5 a = x
6 b = x -1----> 7 return func1(a, b)
ipdb> x
1
ipdb> quit
另外,在 notebooke 中执行 %pdb on 可以设置为当异常发生时自动进入调试模式,在某些特殊的情况下,这么做可能会更为方便:
In [9]:
%xmode Plain
%pdb on
func2(1)
Exception reporting mode: Plain
Automatic pdb calling has been turned ON
Traceback (most recent call last):
File "<ipython-input-9-35491686a29e>", line 3, in <module>
func2(1)
File "<ipython-input-1-d849e34d61fb>", line 7, in func2
return func1(a, b)
File "<ipython-input-1-d849e34d61fb>", line 2, in func1 return a / bZeroDivisionError: integer division or modulo by zero
> <ipython-input-1-d849e34d61fb>(2)func1() 1 def func1(a, b):----> 2 return a / b
3 4 def func2(x): 5 a = x
ipdb> a
1
ipdb> b
0
ipdb> up
> <ipython-input-1-d849e34d61fb>(7)func2() 3 4 def func2(x): 5 a = x
6 b = x -1----> 7 return func1(a, b)
ipdb> x
1
ipdb> quit