(Again not necessarily python specific)
One nice feature of emacs is show-paren-mode. (Naming it show-paren-mode rather than paren-show-mode makes it somewhat less discoverable but I digress). This nice little feature allows one to make sure parens (or brackets or curly brackets) are in order. It does so by visually highlighting the matching pair when the cursor is over the starting one (or after the ending one). It's very useful when you have a long dictionary with lists as values. The emacs wiki page includes a function for showing matching ends when one is offscreen. Very handy indeed.
To enable show-paren-mode type M-x show-paren-mode or put something like this in your .emacs:
;; highlight balanced parens (add-hook 'python-mode-hook (lambda () (show-paren-mode 1)))
Apparently one of the critically acclaimed of Textmate is autopairs (or something like that). People love it cause it saves them a keystroke. If you type an opening paren, it adds a closing paren and moves the cursor inside the parens. Nice! How to get that in emacs?
As always in the open source world, there are many ways. Here's what I went through:
I searched for electric pair and found this entry in the emacs wiki. It's a good start but it has some drawbacks. It only inserts the matching pair when the cursor is at the end of the line (admittedly that's probably the case 80% of the time). So it won't work on nested items (say a string inside a list).
To deal with that first issue I tried skeleton mode. This gets around the embedding issue.
Then I find this blog post illuminating me on the second issue. I didn't think of this at first but if you have electric completes you probably want electric deletes too. So I'm currently using a modified version of his code (added support for single quote). This appears to handle triple quoting that is common in python docstrings too.
Marcelo's blog also mentioned paredit which seems to be quite featureful for lisp source, but has issues with python (no single quotes, space inserted between started paren and previous character, complex source). So I only tried it for a minute or so.
Good luck with your balancing!
Instead of advicing backward-delete-char-untabify it is better to advice
delete-backward-char to have the deleting of pairs also working in non-C
modes like HTML mode.
Good post with correct example... Thank you all your examples are nice and
is clear to understand with your point.
Have a look at http://www.emacswiki.org/emacs/AutoPairs .