Python script debugging

Source: Internet
Author: User

Use the PDB module in Python for debugging.

Import PDB

PDB. set_trace ()

You can also use Python-m pdb mysqcript. py.

(PDB) will automatically stop at the first line, waiting for debugging, then you can look at the help

(PDB) h

Describe these key commands

> Breakpoint settings

(PDB) B 10 # Set the breakpoint to the 10th rows of this py

Or (PDB) B ots. py: 20 # Set the breakpoint to ots. py row 20th

Delete breakpoint (PDB) B # view the breakpoint number

(PDB) Cl 2 # Delete 2nd breakpoints

 

> RUN

(PDB) N # single-step operation

(PDB) s # click it to run, that is, click Next, AND THE METHOD

(PDB) C # jump to the next breakpoint

> View

(PDB) P Param # view the current variable value

(PDB) L # view the code running somewhere

(PDB) A # view all intra-stack variables

(PDB) W lists the layers in the current call stack.

(PDB) D move one layer down in the call stack

(PDB) U moves up a layer in the call stack. If you press N after the first layer, the next description will be executed at the layer after the first step, and the previous function call will be automatically returned.

(PDB) Cl clears the specified breakpoint. If no parameter is provided, all breakpoints are cleared.

(PDB) Disable cancels all breakpoints, but still retains these breakpoints.

(PDB) Enable to restore the breakpoint function.

(PDB) Ignore sets the number of times the breakpoint is ignored. If no count is specified, the initial value is 0. When count is 0, the breakpoint will work normally. If the Count value is specified, the interrupt is executed each time, and the count value is 1 less until the Count value is 0.

(PDB) condition bpnumber [condition]

(PDB) J (UMP) lineno. Jump to a row for execution. It can only be used at the bottom of the call stack.

(PDB) l list the locations in the current file. The continuous l command is always listed at the end of the file. You can use the specified number of rows or range to print.

(PDB) the PP and P commands are similar, but pprint module is used (pprint is not used. For details, refer to Python library reference ).

(PDB) alias replaces "a group of Debugging commands" with an "alias", which is a bit similar to C/C ++'s macro (For details, refer to the python library reference ).

(PDB) unalias cancels an alias.

(PDB) [!] Statement executes description in the current environment (context)

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.