When a Python app crashes, it prints a traceback: a stack of calls ending in the error. Beginners often panic at its length and start changing code at random. The traceback is actually a map. The last line names the error, and the frames above it show the path the code took to reach it. Reading it calmly solves most bugs faster than any other method.
Reading a traceback in order
- Read the last line first: it names the error type and the value that caused it.
- Find your own files in the stack and ignore library frames, since the bug is usually in your code.
- Reproduce the error with the smallest possible input before changing anything.
- Change one thing, rerun, and compare the new traceback with the old one.
Add temporary prints that show actual values at the failing line. Most bugs become obvious once you see what the code really received.