Debugging Python Applications in PyCharm - JetBrains Academy - Learn Programming by Building Your Own Apps
Debugging Python Applications in PyCharm - JetBrains Academy - Learn Programming by Building Your Own Apps
You already know how to execute your code in PyCharm. Unfortunately, working on
your code may get frustrating at some point, and pretty often, you will encounter
difficult situations. In this topic, we're going to discuss what if something goes
wrong and you get execution errors. PyCharm has a special tool to help you solve
these issues – a visual debugger. With it, you can detect the problematic line,
preview the variable values at a breakpoint, and breeze through the suspended
script.
§1. Breakpoints
One of the most common tools to detect undesirable behavior in code is
breakpoints. If you add a breakpoint to a line, this is going to be a line where your
code stops executing. Let's consider a typical workflow: Table of contents:
1. Click the gutter at the executable line of code where you want to set the ↑ Debugging Python applications in
breakpoint. PyCharm
§1. Breakpoints
§4. Conclusion
Discussion
2. Right-click your Python script in the editor and select Debug <script name>
Right beside the Debug tool window, there is the Debug Console. Like the Python
Console, it is interactive, so you can use it to type commands, execute them, and
review results:
Step over steps over the current line of code and takes you to the next line
even if the highlighted line has method calls in it. The implementation of the
methods is skipped, and you move straight to the next line of the caller
method;
Step into steps into the method to show what happens inside it. Use this
option when you are not sure the method is returning the correct result.
Step into my code prevents the debugger from stepping into library classes.
Step out steps out of the current method and takes you to the caller method.
For more actions available during the debugging process refer to Stepping through
the program in the official docs.
§4. Conclusion
Let's sum up:
Report a typo
116 users liked this piece of theory. 5 didn't like it. What about you?