Comparison between python program debugging and c/c ++ Functions

Source: Internet
Author: User

Python program debugging is used by many programmers. The following describes Python-related knowledge in detail. Hope to help you. Python program debugging can also implement a single-step debugging function similar to c/c ++, while the debugging module PDB in python is similar to the Common commands of GDB in c) for convenient debugging.

The following is an example (debug_demo.py ):

 
 
  1. #! /Usr/bin/env python
  2. _ Debug = True
  3. Def debug_demo (val ):
  4. If _ debug:
  5. Import pdb
  6. Pdb. set_trace () # introduce related pdb modules
  7. If val <10:
  8. Print "less than 10"
  9. Elif val <20:
  10. Print "less than 20, but big than 10"
  11. Else:
  12. Print "other condition"

Perform debugging in the command line as follows:

 
 
  1. python debug_demo.py 

In this case, you will enter the gdb-like interface to start related debugging.

 
 
  1. /home/tower/test/python/debug.py(9)debug_demo()  
  2. -> if val <= 10:  
  3. (Pdb) 

You can enter h to view available command sets, which is similar to gdb ). Single-step debugging is very helpful in some situations.

Single-step debugging makes sense for the logic tracking of key parts of the program. Therefore, PDB is similar to GDB in C/C ++ in python. however, compared with GDB, PDB functions are much weaker, so it is impossible to use all the feature of GDB in PDB. it is expected that the PDB will be improved as python is upgraded to version 3.0 and later. it is worth looking forward.

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.