- l – Basically a pointer that points which line is current being executed.
- n – Executes the line.
- c – Continues the code without further debugging.
- q – Quits debugging.
import pdb
pdb.set_trace()
name = input("Enter your name : ")
age = input("Enter your age : ")
print(f"You have entered {name} and {age}")
age = age + 5
print("You'll be {age} in the after 5 years")
P.S : THIS CODE IS WRONG. THIS CODE IS INTENTIONALLY WRITTEN WRONG TO DEBUG IT. DON'T COPY. THE CORRECT CODE IS PROVIDED BELOW THE OUTPUT.
OUTPUT :
> c:\users\dsaya\onedrive\desktop\pythonpractise\oop\debuggin_in_python.py(4)<module>()
-> name = input("Enter your name : ")
(Pdb) l
1 import pdb
2
3 pdb.set_trace()
4 -> name = input("Enter your name : ")
5 age = input("Enter your age : ")
6 print(f"You have entered {name} and {age}")
7 age = age + 5
8 print("You'll be {age} in the after 5 years")
[EOF]
(Pdb) n
Enter your name : Sayan
> c:\users\dsaya\onedrive\desktop\pythonpractise\oop\debuggin_in_python.py(5)<module>()
-> age = input("Enter your age : ")
(Pdb) n
Enter your age : 22
> c:\users\dsaya\onedrive\desktop\pythonpractise\oop\debuggin_in_python.py(6)<module>()
-> print(f"You have entered {name} and {age}")
(Pdb) n
You have entered Sayan and 22
> c:\users\dsaya\onedrive\desktop\pythonpractise\oop\debuggin_in_python.py(7)<module>()
-> age = age + 5
(Pdb) n
TypeError: can only concatenate str (not "int") to str
> c:\users\dsaya\onedrive\desktop\pythonpractise\oop\debuggin_in_python.py(7)<module>()
-> age = age + 5
(Pdb) q
Traceback (most recent call last):
File "c:/Users/dsaya/OneDrive/Desktop/PythonPractise/OOP/Debuggin_In_Python.py", line 7, in <module>
age = int(age) + 5
File "C:\Python385\lib\bdb.py", line 94, in trace_dispatch
return self.dispatch_exception(frame, arg)
File "C:\Python385\lib\bdb.py", line 174, in dispatch_exception
if self.quitting: raise BdbQuit
bdb.BdbQuit
CORRECT CODE :
import pdb
pdb.set_trace()
name = input("Enter your name : ")
age = input("Enter your age : ")
print(f"You have entered {name} and {age}")
age = age + 5
print("You'll be {age} in the after 5 years")