When Python is debugging with Pycharm, how to stop and enter the debugging mode (conditional breakpoint) when a certain condition is met?

We often encounter such debugging problems. For example, there are 1000 times of a for loop, and the error occurs at the 83rd loop. At this time, I want to directly locate the 83rd loop. What should I do?

Very simple, using conditional breakpoints can be achieved.

Proceed as follows:

①Set a variable in the loop body, and the variable name is i.
②Click the mouse on the left side of the code line to add a breakpoint.
③Right-click at the breakpoint, as shown in the following figure after right-clicking:
insert image description here
fill in the trigger condition at the Condition in the above figure: for example, "input condition "i == 83"

insert image description here
After filling in, click "Done" to confirm.

When the debugger finds that i==83, it will pause at the breakpoint and enter the debug mode.

Guess you like

Origin blog.csdn.net/wenhao_ir/article/details/130598551