Debugging python is a pretty painless experience using pdb, the built in standard debugger. The basic usage is to insert breakpoints in the code:
import pdb print('hello world') print('entering breakpoint') pdb.set_trace() sum = 0 for x in range(0, 10): sum += x
When the interpreter hits ‘pdb.set_trace()’ it’ll launch the interactive debugging interface, which lets you investigate the different variables, print things and run calculations. A tutorial on using pdb can be found here.
A really useful trick using this snippet allows for quick debugging anywhere in your code. Place the following lines at the top of your python script:
import signal def int_handler(signal, frame): import pdb pdb.set_trace(frame) signal.signal(signal.SIGINT, int_handler)