Python port of the Common Lisp format function