January 2019
Beginner
318 pages
8h 23m
English
The previous two techniques will start the debugger at the beginning of a Python program. But this third technique is best for long-running processes. To start the debugger within a script, use set_trace().
Now, modify your pdb_example.py file as follows:
import pdbclass Student: def __init__(self, std): self.count = std def print_std(self): for i in range(self.count): pdb.set_trace() print(i) return if __name__ == '__main__': Student(5).print_std()
Now, run the program as follows:
student@ubuntu:~$ python3 pdb_example.py> /home/student/pdb_example.py(10)print_std()-> print(i)(Pdb) continue0> /home/student/pdb_example.py(9)print_std()-> pdb.set_trace()(Pdb)
set_trace() is a Python function, therefore you can call it ...
Read now
Unlock full access