How to debug pycharm

Use Debug to debug code

1. Breaking point

Break point: Click in the blank space of the line number corresponding to the code line.
Breakpoints mark the corresponding lines of code in red.
A breakpoint marks a line of code that will temporarily suspend the program when this line of code is run.
Cancel breakpoint: click again at the same location.
As shown in the figure, two breakpoints are made:
image

2. Breakpoint attributes

image
Show properties: Hover the mouse over the breakpoint to see the key information of the breakpoint (line number and script properties).
Change the properties of this breakpoint: Right-click the breakpoint.
You can try to make personalized changes to the breakpoint properties, and then observe the changes in the icon.

3. Code debugging

  • Method 1: Right-click the code
    image

  • Method 2: Click on the insect
    image

4. Debugging process

Pycharm will perform the following operations:
(1) PyCharm starts running and pauses at the breakpoint
image
(2) The breakpoint corresponds to the line of code Turns blue, the program process has reached the breakpoint, but the code marked by the breakpoint has not yet been executed.
image
(3) The Debug tool window appears, showing the current important debugging information and allowing the user to make changes to the debugging process.
image

5. Debug window icon (from left to right)

image
1.show execution point (F10): Display all current breakpoints and return to the line of code corresponding to the running breakpoint.
2.step over(F8): single-step debugging.
If the line of code contains function a, it will not enter function a, but execute function a in one step
3. step into (F7): single-step debugging .
If the code line contains function a, it will enter function a to perform single-step debugging.
4.step into my code(Alt + Shift +F7): execute the next line but ignore libraries (statements that import libraries)
// 5.force step into(Alt + Shift +F7): Execute the next line ignoring lib and constructed objects, etc.
5. step out (Shift+F8): When executing sub-function a, select this debugging operation to directly Jump out of sub-function a without continuing to execute the remaining code in sub-function a. And return to the previous layer function.
6.run to cursor(Alt +F9) jump directly to the next breakpoint

6. Variable Viewer

Observe the status of variables during debugging. A viewer needs to be set up for it. In the Watches window, click the plus sign and enter the name of the variable you want to view. (For example, enter x here and press Enter.)
image
image

7. Console window

Working mode of the Console window: When we need to view the error information given by the program, or perform some additional temporary operations, we need to do it in this window.
Click the command button in the left toolbar to display the Python command prompt. image
Do a small test here. You can directly compile python code and execute some python commands.
###8. View all breakpoints

Guess you like

Origin blog.csdn.net/deer2019530/article/details/130059736