Mastering PyCharm Transcripts
Chapter: Debugging Python applications
Lecture: Concepts: Debugging

Login or purchase this course to watch this video and the rest of the course contents.
0:01 Let's review some of the concepts that we covered during this debugging section.
0:04 Over here we have our debuggers,
0:08 hit some breakpoint on line ten of
0:11 and you can see all the variables,
0:13 the special variables as well as the ones that are active in this function
0:18 or in this overall module,
0:21 so we've got our data, we've got our fibs generator
0:24 our odd fibs generator and our o going through the loop
0:27 and it looks like we're going through on the number 21 right now
0:31 and we hit a breakpoint right there for some reason,
0:35 so really, really nice and we could also see this in the editor
0:39 so I almost never use this bottom window
0:41 unless I'm trying to expand out a list or something complicated,
0:45 I just look up here, like on line 4 it shows you what data 1, 1, 3, 5, 13, 21
0:51 if you look over on line 9 you know what o is, it's 55
0:54 it's really awesome that PyCharm puts these values into the editor
1:00 and the color is meaningful as well
1:02 so green is kind of green-bluish, it hasn't really changed
1:06 and then it turns orange when it has changed
1:09 for example on line nine it's 55 because that was new.
1:13 So here we can see the data lists, down here we can see the generators
1:17 and here we can see our loop variable o
1:20 which is our odd fibonacci number.
1:23 Sometimes you want to override the values of a program
1:26 it can be really tough to test every little condition
1:29 like if I'm in a web app and I'm logged in
1:31 and I am logged in as a regular user but I want to see what happens
1:34 if I was actually an admin in a particular situation,
1:37 I could go to my user account or the active user account and say
1:41 set the value of is admin to true.
1:44 Notice up here that we have the current value of o is 55
1:50 what if we wanted to test it when it was 72 instead of 55
1:53 we click set value, right click down in this little variables thing, click set value
1:58 and then if we entered 72 instead of having the 55 there
2:01 the program runs as if the value was 72.
2:08 We also watch expressions, not just variables
2:12 variables are usually what you want to see
2:14 but sometimes you want to do some processing with that variable
2:18 or call the function or compare one thing against another,
2:22 so you can put those in here as well,
2:25 you just hit that little plus green thing right there with the glasses
2:28 and then you type in the expression and then that will stay there
2:30 even across the debug sessions, which is great.
2:33 We have breakpoints, you can set breakpoints
2:36 just by clicking here in this little gutter area,
2:39 that toggles them on and off, that's pretty straightforward
2:43 you run your code and it just stops when it hits one of the breakpoints,
2:46 that's super nice already.
2:48 We can also make these conditional,
2:51 if you right click on an existing breakpoint
2:53 you can check whether it's enabled,
2:56 you can come down and actually set a condition
2:59 here we only want to break on this breakpoint
3:01 when our loop variable is greater than 100.
3:04 And if you click more you get even more options
3:06 the ability to say log to the console or remove it once it's hit, things like that.
3:13 And once you've set this, notice right here there's a little question mark
3:18 so it doesn't quite look like every other breakpoint
3:22 maybe it could have a little more difference
3:24 maybe it could have like a bigger color difference or something
3:27 but that's what the question mark means,
3:29 it means it's a conditional break point.
3:31 Also if you check under the more options,
3:35 log message when the breakpoint is hit, you get something like this
3:38 and you can see those interleaved throughout your program
3:41 and they even become a little hyperlink things
3:43 you can take and get back to your code.
3:45 Last thing, you may notice this warning here
3:48 debugger speedups using Cython not found;
3:51 now, you probably won't find it these days,
3:55 PyCharm just released version 2017.3
4:01 and with that, they actually ship these binaries for Windows and for Mac
4:07 so if you're using Windows or Mac and a newer version of PyCharm
4:10 you probably already have these high-speed alternative debugger speedups,
4:15 I think you might still see this on Linux though
4:17 and if that happens, you just highlight the stuff in the quotes
4:20 it says run Python this— just copy that and run it
4:24 and then this message will go away
4:26 and your debugging experience will be a lot faster.