Home  >  Article  >  Backend Development  >  How to debug a program in python

How to debug a program in python

(*-*)浩
(*-*)浩Original
2019-07-02 14:02:375802browse

If you only use print to locate python program problems, then this article is written for you. This article will get you started with the python debugger.

How to debug a program in python

The Python standard library provides a debugger called pdb, which provides most of the common functions required for debugging, such as breakpoints and single-line stepping. , Inspection of stack frame data, etc. Understanding some basic usage and knowledge of python pdb will greatly improve our development skills and efficiency and save time in troubleshooting bugs.

Now we use pdb to debug the following simple python program to demonstrate the basic usage of pdb. (Recommended learning: Python video tutorial)

How to debug a program in python

Run the pdb debugger

Add "-m pdb" to the command line parameters of the python interpreter to start the pdb debugger to debug the application, as follows:

How to debug a program in python

In addition, You can also start the debugger by setting breakpoints in the program. First import the pdb module and call the set_trace function to set a breakpoint where you need to pause.

How to debug a program in python

Directly execute the program with a breakpoint added, and the program will automatically pause at the breakpoint.

How to debug a program in python

For more Python related technical articles, please visit the Python Tutorial column to learn!

The above is the detailed content of How to debug a program in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn