How to debug in Python

Source: Internet
Author: User

Debug is an important debugging technique for coding, which helps developers understand the running process better by setting breakpoints during operation.

Debug in Python is not as intuitive as setting breakpoints in the IDE like Java or C + +.

There are two ways to debug Python: 1. Run in the command line , 2. Run in the script . Both methods require the use of a PDB module.

Mode one: Run on the command line

$ python-m pdb my_script.py

Mode two: Run in script


Where breakpoints need to be set, insert method pdb.set_trace ()

Import PDB def make_bread ():    pdb.set_trace ()    return"I don ' t have time "print(Make_bread ())

Command: After entering the debug state, you can enter the command to debug.

C: (continue) Continue W: (words) Displays the context information for the current line A: (arguments) Prints the argument list of the current function S: (stop) executes the current line and stops at the top one possible time N: (next) Continue execution until the next line of the current function or the function returns a value

How to debug in Python

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.