Reading a traceback
A traceback is the call stack at the moment an error escaped. Read it from the bottom.
Traceback (most recent call last):
File "shop.py", line 9, in <module>
main()
File "shop.py", line 6, in main
print(total([]))
File "shop.py", line 3, in total
return sum(xs) / len(xs)
~~~~~~~^~~~~~~~~
ZeroDivisionError: division by zero- The last line names the error type and message.
- The
Fileline just above it is where the error happened. - Lines further up show who called whom, oldest first.
- Marker lines of
~and^point at the failing part of the line.
If the bottom frame is inside a library, walk up to the last frame in your own code. Most often that is where the wrong value was passed in. Fix the cause, which may be several frames above the crash, rather than only the line that raised.
Your task
Write read_traceback(text) returning (error_type, message, function, line) from a traceback's text: the last line's type and message (message "" if there is none), and the function name and line number (as an int) of the deepest File line.
The explanation opens here once every check passes.