PyCharm: debugging line by line?

To run in debug mode press the 'bug' button (or Shift + F9).

Step over - F8

Step into - F7

Step out - Shift+F8.

Step to next breakpoint (or end) - F9


As @Cyber mentioned, the debugging hotkeys will let you step through line by line, step down into function calls, etc., once you've hit a breakpoint and stopped somewhere.

If you really want to step through each line, you could set a breakpoint somewhere at the very beginning of your code. If you're using a main() function in your code, e.g.:

def main():
    ....    

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

then you could set the breakpoint at the call to main(). (If you're not, you might want to try this approach.)

One other thing I'd point out is PyCharm's easy-to-overlook feature of conditional breakpoints. If you right-click on the breakpoint symbol in the gutter area of the editor, you can type in a condition, like n > 10; the breakpoint only triggers when that line is executed and the condition is met. When you're trying to debug code issues within a recursive function, say, this can simplify things a lot.

I know the last part isn't really what you were asking for, but as your codebase gets bigger, going through each line can get really time consuming. You'll probably want to focus more on things like unit testing and logging with larger projects.

Tags:

Python

Pycharm