I don't normally post naked links here but this recipe in the ASPN Python Cookbook has to go down as the best Python hack I've seen.
Be sure to read the discussion too.
Created: Feb. 16, 2005 Last Modified: Feb. 16, 2005 Author: James Tauber