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