PyCharm: line by line debugging?

I am using PyCharm (community version) for my Python development environment. I want the program to be debugged in turn. So I donโ€™t want every line to be a breakpoint ... Is there a way I could do this?

+6
source share
1 answer

As @Cyber โ€‹โ€‹noted, debugging hotkeys will allow you to step into function calls, etc. as soon as you hit the breakpoint and stop somewhere.

If you really want to go through each line, you can set a breakpoint somewhere at the very beginning of your code. If you use the main () function in your code, for example:

def main(): .... if __name__ == '__main__': main() # Breakpoint here, 'Step Inside' to go to next line 

then you can set a breakpoint when calling main() . (If you do not, you can try this approach.)

Another thing I would like to point out is the simple function of reading PyCharm conditional breakpoints . If you right-click on the breakpoint symbol in the gutter area of โ€‹โ€‹the editor, you can enter a condition, for example, n > 10 ; a breakpoint is only triggered when this line is executed and the condition is met. When you try to debug code problems in a recursive function, let's say this can simplify a lot.

I know that the last part is not what you asked for, but as your code base gets larger, iterating through each line can take a lot of time. You will probably want to focus more on things like unit testing and logging with large projects.

+7
source

Source: https://habr.com/ru/post/970511/


All Articles