-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebugging_python.py
More file actions
55 lines (39 loc) · 1.21 KB
/
debugging_python.py
File metadata and controls
55 lines (39 loc) · 1.21 KB
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
"""
Debugging in Python
Two common debugging techniques:
1. Print statements with f-strings - Quick way to trace values
2. The pdb module - Interactive debugging with breakpoints
PDB Commands:
help : list commands
p <var> : print variable
n : next line
c : continue
q : quit
whatis : show type of a value
"""
import pdb
# =============================================================================
# DEBUGGING WITH PRINT + F-STRINGS
# =============================================================================
def add_two_num(a, b):
result = a + b
print(f"Debug: a={a}, b={b}, result={result}")
return result
print("=" * 50)
print("DEBUGGING WITH PRINT + F-STRINGS")
print("=" * 50)
print()
add_two_num(1, 2)
# =============================================================================
# INTERACTIVE DEBUGGING WITH PDB
# =============================================================================
def div_two_num(a, b):
pdb.set_trace() # Breakpoint
return a / b
print()
print("=" * 50)
print("INTERACTIVE DEBUGGING WITH PDB")
print("=" * 50)
print()
print("Running div_two_num(10, 2) with pdb.set_trace()...")
print(div_two_num(10, 2))