None in Tracebacks
Welcome back. In this video, I’ll show you the most common situation in which
None appears in tracebacks. Let’s go back to the REPL and pick up using the example we were using in the previous video. So, at the time we had created
good_function(), which appends something to a list.
so we’ve added
'f' to our list. The most common situation in which you might find a
None in your traceback is if an object you were trying to work on turned out to be a
None when that wasn’t what you were expecting. So, for instance, if I assign
None to my list and then still try to
append() something to it,
then I get this very common
AttributeError. It’s telling me that this is a
NoneType and that this object has no attribute
append. So this is a very common pattern, and there are some set rules to debug this.
00:56 The example we had here was relatively straightforward, but even if you have a more complex situation, the steps are basically the same. You should look for the attribute that raised the error, and then following from there, go back to the object that this attribute was being called on.
01:18 This is the briefest video in our tutorial because, at a high level, there really isn’t more to it than these three steps. Of course, in practice, it can get quite tricky if your code is complex, but if you stick to these three steps, then you should be able to debug it.
Become a Member to join the conversation.