Debugging Python code

Reading through the third chapter of my bazillion page Python book, I came across a discussion of debuggers.  I’m used to the way Matlab works when debugging – putting little stop buttons on certain lines, and stepping through the code if I need to.  Since my code always has bugs in it, I thought learning about debuggers would be important.  I was surprised to see that the first two recommended ‘debugging’ methods in my book were:  (1) Do nothing!  Just read the error statements, and go to that line in your code and fix it.  (2) Print statements – this lets you print out a message or a variable value, generally enough to tell you what you need to know.  These first two are all I’ve ever used before, and seemed to be fine for me.  Also, the author of the book says those are the only ones he uses.  And he wrote the bazillion page book, so he must know what he’s talking about.  I will stick with these two, but mention the other three just for interest’s sake:  (3) IDE GUI debuggers like IDLE, (4) pdb, a command line debugger that is contained in Python’s standard library, and (5) more specific debugging option such as winpdb.

This information can be found on page 67 of Learning Python.

So, once again, the KISS (keep it simple, stupid) method prevails.  I love it.

Emacs and Python

How do I actually take advantage of Emacs as a Python IDE?  A quick google search turned up this:  Enigma Curry blog post. This post is somewhat beyond me, and makes me a bit scared to try to configure my Emacs to to work with Python.  But I now feel like doing anything else would be wimpy.  I guess there’s also IDLE, which provides a GUI for Python development – and it’s a standard part of the Python system.  But Emacs is cooler, right?

It turns out that if I want to customize Emacs for Python, I’m going to have to find and edit a file called .emacs.  It says that this file should be in the $home_directory, along with a directory called .emacs.d.  I found the .emacs.d directory, but not the .emacs file.  I am missing something obvious, still unsure what I’m doing wrong.

Okay, I just created a .emacs file from one I found online – and I now have a working .emacs file.  The one I’ve got right now has a black background and a different font.  Now to make it do Python stuff.  I’m following a tutorial that can be found here (Setup Perfect Python Environment – Sunshine and Rain of a Developer).  I’m starting off by downloading several packages: python-mode.el , pymacs0.24 , auto-complete.el,  yasnippet.el, rope and  ropemacs.

Later the same night…  I have finally got my very first emacs configuration file.  Here it is (.emacs):

(add-to-list 'load-path "~/.emacs.d/")
(add-to-list 'load-path "~/.emacs.d/plugins")
(require 'auto-complete)
(global-auto-complete-mode t)
(require 'yasnippet-bundle)
(load-library "init_python")

I had to do the whole thing twice too, because I messed up somewhere along the way, and nothing was working at all.  But honestly, I don’t fully know what all this is going to do for me in the end.  Hopefully make my life easier!

Oh, one more note – I had to install Pymacs along the way.  At least, I had a problem, thought installing Pymacs would fix it, installed Pymacs, and it may or may not have fixed the original problem.