CurriculumReading Python Error Messages, for KidsReading a traceback bottom-up
How to Read a Python Traceback (Last Line First)
The last line of a crash names the real problem — read it first, not last.
Reading a traceback bottom-up
Every topic so far, a crash just... happened. Now you're going to learn to actually READ one.
A traceback looks like a wall of text, but the important part is always the LAST line.
gold = 100
print(glod)Output
NameError: name 'glod' is not definedNameError: name 'glod' is not defined. That's Python telling you EXACTLY what's wrong — you tried to use a name that was never created.
Above that last line, the traceback also names a LINE NUMBER — exactly where Python was when it gave up.
Sometimes that line number points at where the mistake ACTUALLY is. Sometimes it points at where a bad value first gets USED — one line later than where it was really created wrong.
golde = 100
print(gold)Output
NameError: name 'gold' is not defined. Did you mean: 'golde'?Python complains on the print() line, but the real fix is one line earlier — golde should have been gold from the start. Notice Python even GUESSES the fix for you: "Did you mean: 'golde'?"
The habit worth building: read the LAST line first (what went wrong), then the line number (roughly where), then look slightly earlier too if the obvious line looks fine.
Check your understanding
A traceback ends with: NameError: name 'plyer' is not defined. What does this tell you?
print(plyer)Why: NameError: name 'plyer' is not defined means exactly what it says — somewhere, code tried to use the name plyer, and Python has never seen it created (no plyer = ... anywhere before that point). Usually a typo for a real variable name.
golde = 100, then print(gold) — where is the traceback's line number likely to point?
golde = 100
print(gold)Why: Line 2 — that's where Python actually tries to use gold and discovers it was never created. The real fix is on line 1 (golde should have been gold), but the traceback can only point at the moment the problem became visible, which is sometimes a line or more after the real mistake. (Python even guesses here — "Did you mean: 'golde'?" — but it can't always do that.)
What you'll practice
This code crashes. Run it once and look at the very BOTTOM line of what appears — that's where Python names the problem. It says NameError: name 'glod' is not defined. glod is a typo for gold. Fix the typo, then print gold.
More from this topic
Reading a traceback bottom-up is one lesson inside Reading Python Error Messages, for Kids — see the full lesson order and what the whole topic covers.
View the full topic →