Linux simple debug Python plan by using PDB

Source: Internet
Author: User

Python's own Debug ToolPak: PDB
#-*-Coding:utf-8-*-def func (num):    s = num *    return sif __name__ = = ' __main__ ':    print ' Debug starting ... '    print ' * ' *    print ' debug ending ... '    num = +    s = func (num)    print s
The PDB library is not referenced in a Python file and can be used when running a python file with a number of parameters:
python-m pdb demo.py
come to the PDB debug interface, debug mode will stop in the first line of the program code line

the ability to run the following command, for example:
B (or break): sets a breakpoint. Set function: b demo.func; set line number: B demo:14 (number of rows)
N (or Next): Run the next line:Step over, skip
C (or Continue): Runs the next breakpoint, without a breakpoint, to the end of the program: Step filter
s (or Step): Enter function,Step into, single-hop
R (or return): Jump out of function, Step return
L (or list): View the current code snippet
Q (or quit): Exits the current debug
p (or print): Print variable values
h (or help): View assistance
cl (Clear): Clear all nodes
disable [Bpnumber[bpnumber]]: The first num breakpoint is invalidated. Enable Failure 10th Breakpoint
Enable [Bpnumber[bpnumber]]: Enables the first NUM breakpoint, enabling 10. Enable 10th Breakpoint
W (where): Print stack information
A (args): Print current function parameter information


Of course we can also use the PDB library function to implement the debug of the py:
For Example: we can use the PDB function: Set_trace ()
def func (num):    s = num *    return sif __name__ = = ' __main__ ':    print ' Debug starting ... '    print ' * ' * 10
   pdb.set_trace ()          print ' Debug ending ... '    num =    s = func (num)    
running the program: Python pdb_demo.py
This means setting a breakpoint line to the program. Will voluntarily execute to print ' py ending ... ' Stop, let the developer continue to trigger the next action. This operation is PY other reference py when, just set a breakpoint advantage.

Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

Linux simple debug Python plan by using PDB

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.