Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

None in Tracebacks

00:00 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.

00:16 I’m going to call it one more time, and let’s append the letter 'f'. Okay,

00:23 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,

00:43 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:10 So now you’ll know which object was None which shouldn’t have been None. Then, step through your code, and try to find out what caused it to become None.

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.

01:34 The next video is the last video. That’s the conclusion video, and there I’ll remind you of the key points that we looked at in this tutorial. I’ll see you there!

Become a Member to join the conversation.