Home >Backend Development >Python Tutorial >How to single-step debug in python

How to single-step debug in python

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-06-25 16:31:037490browse

How to single-step debug in python

How to single-step debug Python? Let me introduce you to single-step debugging:

Method 1: Execute python -m pdb myscript.py

(Pdb) will automatically stop at the first line. Wait for debugging, then you can look at the help.

Method 2: At the beginning of the program being debugged: import pdb and set a breakpoint on your line of code: pdb.set_trace()

Related recommendations: " Python video tutorial

(Pdb) h
Explain these key commands

(Pdb) b 10 #Set the breakpoint at line 10 of this py
or (Pdb) b ots.py:20 #Set the breakpoint at line 20 of ots.py
Delete the breakpoint (Pdb) b #View the breakpoint Point number
(Pdb)cl 2 #Delete the second breakpoint

(Pdb)n #Single-step execution
(Pdb)s #Fine point execution That is to say, it will go down to method
(Pdb)c #Jump to the next breakpoint

(Pdb)p param #View the current variable value
( Pdb)l #View the code executed somewhere
(Pdb)a #View all variables in the stack

import pdb
def tt():
pdb.set_trace()
for i in range(1, 5):
print i
<<< tt()
#这里支持 n p c 而已
< (3)tt()
(Pdb) n

pdb single The step-by-step debugging method is summarized as follows:

How to single-step debug in python

The above is the detailed content of How to single-step debug 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