I recently wanted to do the same kind of thing. See this tread: http://groups.google.com/group/comp.lang.python/browse_thread/thread/f27c3b7950424e1c for details on how to do it.