[Python-ideas] Customizing format()

Nick Coghlan ncoghlan at gmail.com
Wed Mar 18 23:06:52 CET 2009


Terry Reedy wrote:
> I agree.  My impression was that format() was added mostly for
> consistency with the policy of having a 'public' interface to special
> methods, and that .__format__ was added to support str.format.  Hence,
> any new capability of .__format__ must be accessible from format strings
> with replacement fields.

format() was also added because the PEP 3101 syntax is pretty
heavyweight when it comes to formatting a single value:

     "%.2f" % (x)
and  "{0:.2f}".format(x)

Being able to write format(".2f", x) instead meant dropping 4 characters
(now 3 with str.format autonumbering) over the latter option.

Agreed that any solution in this area needs to help with str.format()
and not just format() though.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------



More information about the Python-ideas mailing list