Effective PyCharm Transcripts
Chapter: Debugging Python applications
Lecture: Introduction to debugging tools

Login or purchase this course to watch this video and the rest of the course contents.
0:02 It's time to focus on the debugging capabilities of PyCharm. One of the things I really like about PyCharm is its visual debugging
0:11 and they really make a lot of things about discovering how your code is running super super easy
0:20 and I feel like this in particular is one of the places where the other editors badly fall down, you end up just doing a bunch of print statements
0:28 or you end up in some command line debugger which let me tell you, is not the same type of thing.
0:34 So, let's get into it, let's take a simple little application that's not entirely obvious what it's doing and debug it and play with it using PyCharm.
0:43 So to get started, what we're going to do is you just go up, we have our run configuration and a little play button we've been using
0:50 this time we're going to use debug button for debugging. So that's pretty straightforward and when you run it, it opens up this console
0:56 in the commands there's a bunch of little buttons down here you need to get familiar with, so we'll go through them real quick
1:01 and then we'll do an example of going through this. So first of all, you can click this button to say
1:06 show me where, which file on what line we're running at right now. You might have stepped in a few lines
1:13 and then moved all around trying to figure out what's happening and this is like take me back to where we are,
1:18 what are we doing again, oh yes we're doing this. Down here this is to step over, so if you're in a function and you want to just go down line by line,
1:26 this is the button for you, but if you're in a function and you're like, "I need to go inside this other function that's being called here,"
1:33 then you click step into. Now step into will step into anything, it'll step into packages that you've installed from PyPi,
1:41 and step into even standard library stuff potentially. Sometimes you don't want to go into other people's code you want to just go into your code
1:49 so you click this step into my code button and it will only go into the stuff that you've written not the external pieces which is really nice.
1:56 Sometimes you might have to force that so you can use this button if it's there. Now, when you're inside of a function,
2:04 maybe you've stepped into it, and you are like I'm kind of done here but I want to go up a level and see what's happening
2:10 so you just sort of bail out of one level and go up clicking this step out; and then this other one is really nice, this run the cursor
2:18 so if you're like alright, these five lines are great but I want to go check this out, you put your cursor on that line you just say run to here
2:25 and then you continue debugging, that's great. And sometimes you want a little scratch pad to just say is this thing greater than that other thing,
2:32 if I call this and compare with that it will return true so you can use this evaluate expression,
2:37 it's like a little calculator type thing that pops up, you can type whatever you want in there.
2:42 Notice, we are over here and there's two other green buttons you've got to be careful about which green button you press,
2:48 this one means completely throw away all your work, all of your steps and start over. This one means keep going, stop this, and just run it again.
3:00 So you want to be really careful to press the resume one if that's what you want or the start over one, it's not so big if you missed that one
3:07 but if you mean to keep going and you hit that start over button or even the play button in the upper right, that's going to throw away all your work,
3:14 so be careful about which one you pick here. Finally, before we get started
3:18 there is the debugger tab and there's the console tab in this debug window down here, so before we were looking at the debugger side
3:25 but if there is any program output or if it asks us any questions like type this in, or choose this option
3:31 you have to come over this console window to see that.


Talk Python's Mastodon Michael Kennedy's Mastodon