CoursePython from Scratch to Intermediate · Module 8: Errors, Files and Debugging · part 56 of 75
Part 56 · Module 8: Errors, Files and Debugging

Lesson 4: Debugging: finding what is wrong, step by step

17 min read·14 Oct 2026
Module 8 · Lesson 4 · About 50 minutes · Needs: Module 8 Lesson 1 (tracebacks, try and except), Module 6 Lesson 3 (assert), Module 3 Lesson 3 (repr() and the = specifier)

The situation

Amira wants Tom's old notebook read into the program, so the September loans are not lost. You write a first try at reading it, run it over the twelve lines, and it crashes on the fifth. Tom says there are "a few mistakes" in his typing. Nobody knows how many, or where.

Changing code at random is slow and makes new bugs. This lesson gives you a method and five tools, and finds every fault in the notebook with them.

TOM'S NOTEBOOK: 12 LINES 1 2 3 4 5 6 7 8 9 10 11 12 parse_line runs lines 1 to 4, then line 5 crashes KeyError 'Frankenstien' on line 5 method + 5 tools find every fault
The first-try parser gets through lines 1 to 4 (green) and crashes on line 5 (red, an error); the rest are never read, so the lesson needs a method to find every fault.

The rest of this part opens with an account

Signing up is free and takes one email. Nothing to pay, and nothing renews.