1. Use `python -i your_script.py` to execute your program with interactive mode. This means, after your program finishes executing, or your program crashes in the midway, you will enter a python shell.
2. Suppose your script has a bug so that you enter the python shell after it crashes. Now you can play with pdb by:
import pdb pdb.pm() # print your variables or do whatever you want