Speaking of hitting a bug, it’s inevitable once you start writing complex programs that you’ll run into bugs in your code. It happens to all of us! Don’t let bugs frustrate you. Instead, embrace these moments with pride and think of yourself as a bug bounty hunter.
When debugging, it’s important to have a methodological approach to help you find where things are breaking down. Going through your code in the order in which it is executed and making sure each part works is a great way to do this.
Once you have an idea of where things might be breaking down, insert
import pdb; pdb.set_trace() into your script and run it. This is the Python debugger and will drop you into interactive mode. The debugger can also be run from the command line with
python -m pdb <my_file.py>.