The Python program is highly efficient to debug

Source: Internet
Author: User

Now I'm in the Debug Python program just simply print it out in the wrong place, and don't know if Python has a single-step debugging tool like some C + + ides? Or how does the Python God debug his own Python program in general?

You should've used IPython, right? Imagine, would it be nice to automatically take you to the IPython Shell when throwing an exception? And unlike normal Ipython, this time you can call commands such as P (print), up stack, and down stack. You can also create temporary variables and execute arbitrary functions.

In fact, this is achievable and simple, but you need to install IPython first. Then save the following code as ' crash_on_ipy.py '
Import SYS class Exceptionhook:    = None    def __call__ (self, *args, **kwargs):        if self.instance Is None: from            IPython.  Core Import ULTRATB            self. Instance = ULTRATB. FORMATTEDTB (mode= ' Plain ',                 color_scheme= ' Linux ', call_pdb=1)        return Self.instance (*args, * *kwargs) sys. Excepthook = Exceptionhook ()# why ask? Hovertree.com

You can then import crash_on_ipy somewhere in your project code.

This method does not require the IDE.

Recommendation: http://www.cnblogs.com/roucheng/p/pythonstring.html

The Python program is highly efficient to debug

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.