[Python-Dev] Formatting mini-language suggestion

Nick Coghlan ncoghlan at gmail.com
Thu Mar 12 02:06:29 CET 2009


Raymond Hettinger wrote:
> The current formatting mini-language provisions left/right/center
> alignment, prefixes for 0b 0x 0o, and rules on when to show the
> plus-sign.  I think it would be far more useful to provision a simple
> way of specifying a thousands separator.
> 
> Financial users in particular find the locale approach to be frustrating
> and non-obvious.  Putting in a thousands separator is a common task for
> output destined to be read by non-programmers.

+1 for the general idea.

A specific syntax proposal:

  [[fill]align][sign][#][0][minimumwidth][,sep][.precision][type]

'sep' is the new field that defines the thousands separator. It appears
immediately before the precision specifier and starts with a leading comma.

I believe this syntax is unambiguous and backwards compatible because
the only other place a comma might appear (the fill field) is required
to be followed by an alignment character.

Cheers,
Nick.

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


More information about the Python-Dev mailing list