How to read a Python traceback
A traceback looks scary and is actually a map. Read it from the bottom.
Start at the last line
A Python traceback lists the calls that led to the error, with the newest at the bottom. The last line says what went wrong: the type of error, then a colon, then a message. Here is a real one, produced by a small program that prints a name that was misspelt:
Traceback (most recent call last):
File "main.py", line 2, in <module>
print(totl)
^^^^
NameError: name 'totl' is not defined. Did you mean: 'total'?
The type is NameError (a name was not found). The message names totl. Python even suggests total. In many cases this last line is all you need.
Then look at the line just above
The line above the error type shows the code that failed, with carets (^^^^) under the part that Python is complaining about in recent versions. Above it, File "main.py", line 2 tells you where. Open that file at that line.
The chain of calls
When the error is inside a function that was called by another function, the traceback has several File ... entries. Read them from top to bottom as "who called whom": the first is where your program started, the last is where it broke. Often the real mistake is in the last entry that belongs to your code, not in the library code below it. Lines that point into the Python installation or site-packages are library internals; scroll up to the last line of your own file.
The common error types, in one line each
| Type | Usually means |
|---|---|
SyntaxError | The code is not valid Python (a missing colon, bracket or quote) |
IndentationError | The spaces at the start of a line are wrong |
NameError | A name is not defined (typo, or used before it exists) |
TypeError | An operation got the wrong kind of value (text plus number, wrong number of arguments) |
ValueError | The kind is right but the value is not (int("abc")) |
IndexError, KeyError | A position or a key that does not exist |
AttributeError | The object has no such method or field |
ImportError, ModuleNotFoundError | A module could not be imported |
FileNotFoundError | A file or folder is not where the program looked |
ZeroDivisionError | A division by zero |
Every one of these has its own page on this site, with the code that makes the error, the exact output and the fix.
A method that works
- Read the last line. Say it out loud in plain words.
- Open the file and line named in the last
Fileentry that belongs to your code. - Print or inspect the values on that line just before it runs:
print(type(x), x). - Change one thing and run again.
- If you are stuck, copy the last line (not the whole traceback) into a search, together with the word Python.
Why does the traceback say "most recent call last"?
It shows the calls in order, so the one that failed is at the bottom, closest to the error message.
What does "During handling of the above exception, another exception occurred" mean?
An error happened inside an except block while handling another error. Read both: the first is the original problem.
This is an independent guide. It is not connected with Python, Microsoft, Google, GitHub or the Git project. Product names belong to their owners. Examples were run on 13 November 2026 in a practice folder or a blank workbook; your version may word a message slightly differently.