Here in this article, I'd just cover how to step through your standalone Python code and debug it using Emacs as the editor/IDE. First of all you have to install the following Emacs extension modules and Python debugging tools.
- Install Pymacs from this github site and thank François Pinard of Montreal for programming it
- Install Rope and Ropemacs from here (using Mercury)
- Check if you have PDB, just by typing it on command window (you'd mostly have)
Now the step-by-step debugging goes like this
- With your Python program on buffer, type M-x pdb. It would ask if you want to run PDB like, pdb a.out. Replace a.out with your Python module name. In the screenshot, it is adder.py (doing nothing useful).
- This opens a new PDB windows (Screenshot)
- Go to the lines where you need breakpoint, type C-x
(you can notice the screenshot for the statement about it). If you are using Ubuntu, you get a very good look-n-feel, like that screenshot.
- Type c on the PDB buffer to run upto the breakpoint
- From the breakpoint, n for next line or s to explore into functions on that line. In Ubuntu, you'd have a GUI to assist you.
- To watch a variable, type p var, as in the screenshot.
- Any time during debugging, w prints out the stack and u and d lets you go up and down the stack.
For most of the standalone Python script, this would improve your productivity a lot. You can do more complex debug operations, but this is a very good start.