[Python-3000] Implementing % formatting in terms of str.format()

Eric Smith eric+python-dev at trueblade.com
Thu Apr 10 01:54:31 CEST 2008


I'm working on issue 2416, adding %b to % formatting 
(http://bugs.python.org/issue2416).  It's really quite a pain, 
especially in 2.6 with int and long and str and unicode.

I'm contemplating just making % formatting compute a new format string 
and call str.format (or obj.__format__, or something appropriate).  But 
before I proceed, I thought I'd ask and see if this really offends 
anyone.  By implementing % in terms of str.format, I hope to be able to 
delete a lot of the duplication in the formatting code, but I haven't 
checked yet to see what's possible.  The real impetus is issue 2416, though.

About the only downside I see is that str.format is somewhat slower than 
%, but I can probably get around most of this by directly calling 
int.__format__, float.__format__, etc.  Other than misleading 
microbenchmarks, I've never really compared the difference, though.	



More information about the Python-3000 mailing list