Simple Guide for using PDB to debug Python programs, and a simple guide for using pdb to debug python
In Python, you can also debug programs like gcc/gdb, as long as you introduce the pdb module when running the
Debug is a very important skill for any developer and it can help us pinpoint errors and find bugs in the program. Python offers a range of debug tools and packages that we can choose from. This article will mainly explain how to use the Python debug related tools for Debug.
debugging using the PDBThe PDB is a Python-
Introduction to Python program debugging in PDB mode and python debugging in pdb Mode
I used the idel feature in windows to debug python programs. I have not debugged python programs in linux. (Most of the time it's just print) se
This article mainly introduces how to use the pdb module to debug Python program instances. This article focuses on pdb. run () function, pdb. runeval () function, pdb. runcall () function, pdb. the use of set_trace () functions a
Label:Excerpt from: http://www.91linux.com/html/article/program/python/20111119/22356.html This article explains how to use the PDB for Python debugging.When at hand Without the IDE, you can refer to this article if you are worried about Python debugging. (PDB command Debugg
Tags: OCA script summary Pytho class ALS Erro turn code snippetThe debug feature is very important for developer, and Python provides the appropriate module PDB so that you can debug with a text editor to write scripts. The PDB is the abbreviation for Python debugger.Some of the commonly used commands are:Command useBr
Use the PDB library debugging program in Python and the pythonpdb library debugging
The pdb library that comes with Python finds that it is very convenient to use pdb to debug the program. Of course, pdb cannot be used for remote
Python built-in PDB library, found to use PDB for debugging
Program It is still very convenient. Of course, PDB may be confused about remote debugging and multithreading.
There are multiple ways to debug with PDB:
1. Run the command line to start the target program an
Python's own PDB library found it handy to debug a program with a PDB, and of course, what remote debugging, multithreading, and so on, the PDB is uncertain.
There are several options to use PDB debugging:
1. Command line to start the target program, plus the-m parameter, so call myscript.py Word breakpoint is the ex
is actually an interactive source code debugger.
You need the following two lines of code to use this module.
Import PDB
pdb.set_trace ()
Take a look at the program we've modified, which contains some breakpoints.
Import PDB
import sys
def add (num1=0, num2=0): return
int (NUM1) + int (num2)
def sub (num1=0, num2=0): return
Int (NUM1)-int (num2)
def main ():
#Assuming Our input
followed by the statement, you can directly change a variableQ (uit), exit debugFind it interesting to debug a program at the command line, record it and share it. W, Print a stack trace, with the most recent frame at the bottom. An arrow indicates the ' Current frame ', which determines the context of the most commands. ' BT ' is a alias for this command. D, Move the current frame one level down in the stack tra
, you can directly change a variableQ (uit), exit debugFind it interesting to debug a program at the command line, record it and share it.W, Print a stack trace, with the most recent frame at the bottom. An arrow indicates the ' Current frame ', which determines the context of the most commands. ' BT ' is a alias for this command.D, Move the current frame one level down in the stack trace(to a newer frame).
is actually an interactive source code debugger.
You need the following two lines of code to use this module.
import pdbpdb.set_trace()
Let's take a look at our modified program, which contains some breakpoints.
import pdbimport sysdef add(num1=0, num2=0): return int(num1) + int(num2)def sub(num1=0, num2=0): return int(num1) - int(num2)def main(): #Assuming our inputs are valid numbers print sys.argv pdb.set_trace() #
3. Execute the program to trigger the debugger
Once the breakpoint is
Tags: python pdbin Python, syntax errors can be found by the Python interpreter, but logical errors or variable usage errors are not easy to find, and if the results do not meet expectations, debugging is a good debugging tool: The PDB module that comes with Python. The
waiting to continue debugging N means next
# 3 Viewing the value of a variable
# p----> be able to see the value of the variable, p indicates the meaning of the Prit printout
#例如:
# p name indicates the value of view variable nameDemo 2import pdb
="aaa"
pdb.set_trace()
="bbb"
="ccc"
pdb.set_trace()
=++ c
print(final)
# 《4 将程序继续运行》
# c----->让程序继续向下执行,与n的区别是n只会执行下面的一行代码,而c会像python xxxx.py一样 继续执行不
This article mainly introduces the use of PDB modules to debug Python program instances, this article focuses on the Pdb.run () function, Pdb.runeval () function, Pdb.runcall () function, Pdb.set_trace () The use of functions and the PDB debugging commands and so on content, the need for friends can refer to the following
In
Tags: des http io ar os using SP for strongThe debug feature is very important for developer, and Python provides the appropriate module PDB so that you can debug with a text editor to write scripts. The PDB is the abbreviation for Python debugger.Some of the commonly used commands are:
Command
Use
Tags: python pdb trace debugPoetry is a melancholy medium, and the poet's mission is lonely;--North "The Rose of Time"Learning is a deep ballad, and our task is to enjoy him. --Little Q "20161203"------------------------------------------------------------------------------------------------Learn C + +, the teacher taught us to have GDB debugging tools, in the wo
code of the main module to be debugged below
#! /Usr/bin/python #-*-coding: UTF-8-*-def sub (a, B ): return a-bif _ name _ = "_ main _": print ''import testFun I = 0 a = 1 while (I
Summarize common commands
Basic commands
H (elp) command: the available commands of the current version of Pdb are printed. to query a command, enterh [command] For exampleh l View list commands
L (ist) command: list the code
the running state at any time. # err.py
s = ' 0 '
n = Int (s)
print 10/n
$ python-m pdb err.py
>/users/michael/github/sicp/err.py (2) After starting with the parameter-m PDB, the PDB navigates to the next code to execute, s = ' 0 '. Enter command l to view the code: (PDB
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.