What command do we use to debug a Python program?

I tried this but didn’t Work

Microsoft Windows [Version 10.0.16299.248]

© 2017 Microsoft Corporation. All rights reserved.

C:\Users\lifei> cd Desktop

C:\Users\lifei\Desktop>

Then, we run the following command (for file try.py):

C:\Users\lifei\Desktop>python -m pdb try.py

> c:\users\lifei\desktop\try.py(1)<module>()

-> for i in range(5):

(Pdb)

There’s a couple of different ways to debug Python, depending on what you’re using for development.

One is putting in print statements to check values and then running from a text editor like Geany (which has an Execute button) or in the command line. It looks like you’re trying the command line but having issues. Maybe try taking out the flags. I’ve never tried running a Python script from the command line with anything but “python myscript.py”. Maybe you have some good reason for the flags being there. Honestly, I know squat about them.

The second is stepping your Python code. This is my preferred method. You can do this with VS Code. If you’re at all familiar with Visual Studio, it’s awesome.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.