Read the Traceback
读 traceback
Parse a Python traceback as a string. Read it bottom-up: last line = error type, deepest frame = where the bug is.
Anatomy
Traceback (most recent call last):
File "letter_grade.py", line 19, in <module>
print(letter_grade(85))
File "letter_grade.py", line 12, in letter_grade ← deepest frame, usually the bug
return grade
NameError: name 'grade' is not defined ← error type + message The two helpers
Python · runnable
The common runtime errors
| Error | Most likely cause |
|---|---|
NameError | Typo or used-before-defined |
TypeError | Wrong type or arg count |
IndexError | Index out of range |
KeyError | Dict key not present |
AttributeError ... NoneType ... | Function returned None; you called .x on it |
RecursionError | Forgot the base case |
ZeroDivisionError | Divided by 0 |