Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
One, the point of interruption
A breakpoint marks a line of code that suspends the program when Pycharm runs to it. Note that the breakpoint marks the line of code in red, and cancelling the breakpoint is as simple as clicking again at the same location.
When you hover your mouse pointer over a breakpoint, Pycharm displays the key information, line number, and script properties of the breakpoint. If you want to change the properties of the breakpoint, right click:
You can try personalizing the breakpoint property and then watch the icon change.
Second, code debugging
(1) PyCharm starts running and pauses at a breakpoint
(2) The line of code where the breakpoint is located turns blue, which means that the Pycharm program has reached the breakpoint but has not yet executed the code marked by the breakpoint.
(3) The Debug Tool window displays important debugging information and allows you to modify the debugging process.
3. Debug button
1.
Show Execution Point (F10) shows all current breakpoints
2,
Step over(F8) Single-step debugging. If there is A sub-function A in function A, the single step debugging will not be carried out in sub-function A, but the sub-function A is treated as A whole and executed in one step
3,
Step into(F7) Single-step debugging. If A subfunction A exists in function A, step debugging is performed in subfunction A. (Enter python modules and modules you write)
4,
Step into my code(Alt + Shift +F7) Execute the next line but ignore libraries
5,
Force step into(Alt + Shift +F7) Perform the next line to ignore the lib, construct the object, etc
6,
Step out (Shift+F8) Step out (Shift+F8) Step out (Shift+F8) Step out (Shift+F8) Step out (Shift+F8) Step out (Shift+F8) Step out (Shift+F8)
And returns the function at the previous level.
7,
Run to cursor(Alt +F9) jumps directly to the next breakpoint. The code executes to the line where the cursor is located
Eight,
You can keep doing whatever you want
4. Watch Window
In the Watches window, click the plus sign, enter the name of the variable you want to view, and then press Enter. When a variable is not defined, we can define it in the console or by performing the next step, using an assignment in the code.
Console window: This is where you can directly compile Python code and execute python commands.
Sixth, pay attention to
Sometimes the debug does not work properly and the console will output the following message:
There should be no errors in the program itself, but normal debugging is not possible.
Note the following solutions:
1. Close Pycharm, delete the. Idea folder in the project directory, and restart.
2. Delete all breakpoints. You can do this by clicking on the two overlapping red origins shown in the image below.
3, Click on Pycharm’s File>>Invalidate Caches/Restart… And select Invalidate and Restart. This action clears the cached information in the project.
4. Rebuild the entire project and reconfigure it.
These four methods may solve this problem, I tried the third, then the second should also work, the first and fourth carefully try.