1. Debugging process
Debugging is a skill every developer must have, useful in daily development and bug hunting.
The debugging process is divided into three steps:
-
Step 1: Make a breakpoint where you want to debug
-
Step 2: Run the Python program in debug mode
-
Step 3: Use a variety of tools to start code debugging
So first step one and step two, I’m going to draw them in this picture
Click on the spider above to enable debug mode and a TAB pops up under PyCharm.
This TAB has many keys, including
- Variable view window
- Debug control window
- Thread control window
- Program control window
In the variables view window, you can view the current program up to the breakpoint, all normal and special variables, which are subject to change each time you execute a line of code.
If your program is multithreaded, you can switch threads by using the drop down box in the thread control window.
Above two Windows, are relatively simple, I brush over, the main focus of the next debugging control button and program control button.
In the debug control window, there are eight buttons. What are their functions?
- Show Execution Point: Wherever the cursor is in your code editing window, clicking this button will automatically redirect you to where the program is running.
- Step Over: in Step execution, when encountering a sub-function in a function, it will not Step into the sub-function, but finish the whole sub-function and then stop, that is, treat the whole sub-function as one Step. It is the same as step into if there are no subfunctions. In simple terms, the program code passes over the subfunctions, but the subfunctions execute and do not enter.
- Step Into: In Step execution, when encountering a subfunction, enter and continue the Step execution, some will jump to the source code to execute.
- Step Into My Code: When a subfunction is encountered, it enters and continues to Step without entering the source Code.
- Step Out: If you’re inside a function body and you’ve looked at two lines of code that you don’t want to look at, Step Out of the body of the current function and return to the place where the function was called.
- 4. Run To Cursor: To Run To the Cursor without having To hit a breakpoint each time.
- Evaluate Expression: Evaluate Expression in which you can execute some code yourself.
The above seven functions, is the most commonly used functions, the general operation step is, set a breakpoint, debug run, and then F8 single-step debugging, encountered want to enter the function F7, want to come out in shift + F8, skip do not want to see the place, directly set the next breakpoint, and then F9 past.
Just look at this picture.
In the program control window, there are six buttons. What are their functions? In the meantime, look at the picture below.
2. Debug related shortcut keys
- ⇧ + F9: Debug the current file
- ⌥ + ⇧ + F9: a pop-up menu allowing you to select which file to debug
- F8: step by step without entering the function
- F7: Step into the function
- ⌥ + ⇧ +F7: single step, accessing only self-written functions
- ⇧ + F8: jump out of the function
- F9: Runs to the next breakpoint
- ⌥ + F9: Run to the cursor
- ⇧ + ⌘ + F8: Check all set breakpoints
- ⌘ + F8: Toshop breakpoints (cancells breakpoints if they exist, adds breakpoints if they do not)
- ⌥ + F5: Run again in debug mode
- ⌥ + F8 evaluates the expression (you can change the value more to make it work)
At the end of this article, I will introduce two online documents written by myself:
The first document: PyCharm Chinese Guide 1.0 document
I sorted out 100 Tips on using PyCharm. I spent a lot of time recording hundreds of GIFs for beginners to be able to use them directly. If you are interested, you can read online documents.
Second document: PyCharm Dark Magic Guide 1.0 document
The system includes a variety of cold Python knowledge, Python Shell diverse gameplay, crazy Python skills, Python super detailed advanced knowledge interpretation, very practical Python development skills.