Debugging Python Errors Calmly
Read tracebacks, find the real cause and fix common Python errors without guessing or panic.
A taste of a lesson
I get AttributeError: 'NoneType' object has no attribute 'append'. What is happening?
It means the variable you called append on holds None, not a list. So the question is where it became None. A very common cause is assigning the result of a method that changes things in place, such as items = items.sort() or items = items.append(x); those methods return None. Another is a function that forgets to return its list. Look a few lines above the failing line for where that variable was last assigned. What does that line say?
Written by the teacher as an example. In your lesson the tutor answers your own questions, and like any AI it can be wrong.
What you will be able to do
- Read a traceback from the bottom and find the line in your own code that failed
- Recognise and fix the most common Python error types
- Inspect values with print, repr and the built in debugger
- Shrink a problem to a minimal example before asking for help
- Check AI suggested fixes against the real cause before applying them
Lesson plan
- 1 Reading a traceback bottom up Find the error type, the message and the failing line in your own code. Start
- 2 The common errors in data scripts Recognise NameError, TypeError, KeyError, IndexError, ValueError and AttributeError on sight. Start
- 3 Looking inside with print and repr Inspect values and types at the point of failure. Start
- 4 Using the debugger Pause a running script and step through it with breakpoint(). Start
- 5 Minimal examples and asking for help Shrink a bug to a few lines and write a help request that gets good answers. Start
Try asking
About this tutor
For beginners who see a red traceback and freeze, or who fix errors by randomly changing lines until something works. You learn to read a traceback from the bottom up, recognise the most common error types in data and AI scripts, inspect values at the point of failure with prints and the built in debugger, and shrink a problem to a minimal example. The tutor also shows how to ask for help well, from a colleague or an AI assistant, and how to check the suggested fix instead of pasting it blindly. Bring your own errors; they make the best exercises.
Reviews
Students can review a tutor after a paid lesson. Nobody has yet.
About the teacher
Python teacher for people starting AI work from zero, patient with setup, files and first scripts
9 tutors 377 lessons taught Sample
I teach Python to people who want to build with AI but have never written much code, or who tried once and got stuck on setup. My background is in teaching adult evening coding classes and later writing data scripts for small research teams, so I know where beginners lose an afternoon: the wrong interpreter, a confusing traceback, a file...
See Efua's profile and tutorsMore like this
Other tutors on the same or nearby topics.