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?
Reply content:
This is a rage to answer.
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 SYSclass Exceptionhook: instance = 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()
To function like GDB, you can use the PDB, for example:
Import PDB
Pdb.set_trace ()
Add the above 2 lines to the code that needs to add a breakpoint, run, the execution can be interrupted here, one step, continue, view variable values and other functions have, may wish to help under. Recommended Pycharm
Nice ide,designed for python~, support Win,linux,maxos
Support for breakpoint debugging, self-with connector (Github,mantis,jira,bugzilla)
It's better than eclipse if you don't consider mixed-language programming.
Interface such as:
Personal use experience is good, but under MacOS System, configuration interpreter to a little toss.
Website Portal: http://www. jetbrains.com/pycharm/
A picture wins thousands of words, the upper left is the call stack, the top right is the variable value, the bottom is currently running to that line of code, more efficient than the debug mode such as print.
With the eclipse+pydevpython-m PDB your.py I recently used the pudb, feeling a bit friendlier than the PDB. The command-line installation of Linux is simple:
pip install pudb
Perennial Print+type of passing ~ must be Ipython. The best time to debug a program is when the program is in error, sometimes running out of error and then invoking the debugger to reproduce it again may not be reproducible, or reproducing the error will take a long time to run. And in the Ipython run the program can be in error the first time debugging, look at the contents of the stack, is absolutely convenient. Try the next vs2015 of the PY components, feel no worse than pycharm year-round vim or textmate. Debug Print.dir, type, and so on. I don't understand the PDB.