[Python-ideas] Customizing format()

Raymond Hettinger python at rcn.com
Wed Mar 18 01:34:16 CET 2009



> Where conventions is an optional dictionary with formatting control values.  Any value object can accept custom controls, but the 
> names for standard ones would be taken from the standards provided by localeconv():

Forgot to mention that this approach make life easier on people writing __format__ methods because it lets them re-use the work 
they've already done to implement the "n" type specifier.

Also, this approach is very similar to the one taken in Java with its DecimalFormatSymbols object.  The main differences are that 
they use a custom class instead of a dictionary, that we would use standard names that work well with localeconv(), and that our 
approach is extensible for use with custom formatters (i.e. the datetime module could have its own set of key/value pairs for 
formatting controls).



Raymond 




More information about the Python-ideas mailing list