[Python-ideas] Customizing format()

Raymond Hettinger python at rcn.com
Wed Mar 18 21:37:47 CET 2009

>> # DE and US dicts as per Raymond's format() example
>> fmt = "The value is {:,.5f}{!conv}"
> A new conversion specifier should follow the current pattern and be a 
> single letter, such as 'c' for 'custom' or 'd' for dict.
> If, as I would expect, str.format scans left to right and interprets and 
> replaces each field spec as it goes, then the above would not work. So 
> put the conversion field before the fields it applies to.

My interpretation is that the conv-dictionary applies to the whole
string (not field-by-field) and that it can go at the end (because
it doesn't affect parsing, rather it applies to the translation phase).


More information about the Python-ideas mailing list