Raymond Hettinger posted this recipe to the Python Cookbook. I've not tried it myself, but it sounds like what you're looking for. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/277940 -- Paul