포스트

Debugging

Debugging

Debugging

예외제어: %xmode

1
2
3
4
5
6
7
8
def func1(a, b):
    return a / b


def func2(x):
    a = x
    b = x - 1
    return func1(a, b)
1
func2(1)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
---------------------------------------------------------------------------

ZeroDivisionError                         Traceback (most recent call last)

Cell In[2], line 1
----> 1 func2(1)


Cell In[1], line 7, in func2(x)
      5 a = x
      6 b = x - 1
----> 7 return func1(a, b)


Cell In[1], line 2, in func1(a, b)
      1 def func1(a, b):
----> 2     return a/b


ZeroDivisionError: division by zero
1
2
%xmode
Plain
1
Exception reporting mode: Plain
1
func2(1)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Traceback (most recent call last):


  Cell In[4], line 1
    func2(1)


  Cell In[1], line 7 in func2
    return func1(a, b)


  Cell In[1], line 2 in func1
    return a/b


ZeroDivisionError: division by zero
1
2
%xmode
Verbose
1
Exception reporting mode: Verbose
1
func2(1)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
---------------------------------------------------------------------------

ZeroDivisionError                         Traceback (most recent call last)

Cell In[6], line 1
----> 1 func2(1)


Cell In[1], line 7, in func2(x=1)
      5 a = x
      6 b = x - 1
----> 7 return func1(a, b)
        a = 1
        b = 0


Cell In[1], line 2, in func1(a=1, b=0)
      1 def func1(a, b):
----> 2     return a/b
        a = 1
        b = 0


ZeroDivisionError: division by zero

역추적 내용으로 불충분할 경우: %debug

1
%debug
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
> c:\users\jiinn\appdata\local\temp\ipykernel_2956\4210028810.py(2)func1()



ipdb>  list


      1 def func1(a, b):
----> 2     return a/b
      3 
      4 def func2(x):
      5     a = x
      6     b = x - 1
      7     return func1(a, b)



ipdb>  print(a)


1


ipdb>  print(b)


0


ipdb>  exit
1
%debug
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
> c:\users\jiinn\appdata\local\temp\ipykernel_2956\4210028810.py(2)func1()



ipdb>  list


      1 def func1(a, b):
----> 2     return a/b
      3 
      4 def func2(x):
      5     a = x
      6     b = x - 1
      7     return func1(a, b)



ipdb>  up


> c:\users\jiinn\appdata\local\temp\ipykernel_2956\4210028810.py(7)func2()



ipdb>  list


      2     return a/b
      3 
      4 def func2(x):
      5     a = x
      6     b = x - 1
----> 7     return func1(a, b)



ipdb>  print(x)


1


ipdb>  up


> c:\users\jiinn\appdata\local\temp\ipykernel_2956\2483606204.py(1)<module>()



ipdb>  list


----> 1 func2(1)



ipdb>  down


> c:\users\jiinn\appdata\local\temp\ipykernel_2956\4210028810.py(7)func2()



ipdb>  list


      2     return a/b
      3 
      4 def func2(x):
      5     a = x
      6     b = x - 1
----> 7     return func1(a, b)



ipdb>  exit
1
2
%xmode
Plain
1
Exception reporting mode: Plain
1
2
%pdb
on
1
Automatic pdb calling has been turned ON
1
func2(1)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
Traceback (most recent call last):


  Cell In[11], line 1
    func2(1)


  Cell In[1], line 7 in func2
    return func1(a, b)


  Cell In[1], line 2 in func1
    return a/b


ZeroDivisionError: division by zero



> c:\users\jiinn\appdata\local\temp\ipykernel_2956\4210028810.py(2)func1()



ipdb>  list


      1 def func1(a, b):
----> 2     return a/b
      3 
      4 def func2(x):
      5     a = x
      6     b = x - 1
      7     return func1(a, b)



ipdb>  print(b)


0


ipdb>  exit
이 기사는 저작권자의 CC BY-NC 4.0 라이센스를 따릅니다.