SoFunction
Updated on 2024-10-30

Implementing the process of debugging a program using PyCharm

1. Prepare the code

# coding=utf-8
 
class TestDebug:
    def __init__(self):
         = 1
         = 2
 
 
    def test01(self):
        print('test01 has begun!')
        self.test02()
        print('test01 is over!')
 
 
    def test02(self):
        print()
        print()
        c = 3
        print(c)
 
 
if __name__ == '__main__':
    obj_test_debug = TestDebug()
    obj_test_debug.test01()

2. Use PyCharm to open the program you want to debug.

3. Set a breakpoint at the location where the code needs to be debugged.

Just left-click on the position after the line number and click again to cancel setting the breakpoint:

4. Right-click on debug

Or click the debug button in the upper right corner or shift+F9 to debug:

5. After starting debugging

The program stops at the set breakpoint, the current line of program execution is marked in blue, and the Status Variable View window below shows the current value of the variable:

6. Debugging shortcuts

  • F9 Continue running the program
  • F8 Execute the next statement
  • F7 Enter the function of the current statement

7. After entering the console

Click the python icon below to open the interactive debugging mode, in the interactive debugging mode, you can enter Python statements in the Console paging, and the execution environment of the statement is the same as the current call stack breakpoint execution environment.

As shown in the figure, enter d = + and return to the debugger screen to see d = 3:

The above is a personal experience, I hope it can give you a reference, and I hope you can support me more.