[Python-ideas] Rough draft: Proposed format specifier for a thousands separator (discussion moved from python-dev)

Terry Reedy tjreedy at udel.edu
Sat Mar 14 20:03:19 CET 2009


spir wrote:

> I have the impression, but I may well be wrong, that contrarily to a
> format, a *formatted number* instead seems easy to scan -- with human
> eyes. So, as a crazy idea, I wonder whether we shouldn't let the user
> provide a example formatted number instead. This may address most of
> use cases, but probably not all.
> 
> To makes things easier, why not specify a canonical number, such as
> '-123456.789', of which the user should define the formatted version?
> Then a smart parser could deduce the format to be applied to further
> numbers. Below a purely artificial example.
> 
> -123456.789   -->   kg 00_123_456,79-
> 
> format: unit: 'kg' unit_pos: LEFT unit_sep: ' ' thousand_sep: '_' 
> fract_sep : ',' sign_pos: RIGHT sign_sep: None padding_char: '0'

Once the .format language is expanded to be able to define grouping 
separators, one will be able to define functions to turn such templates 
in field specs. Now many options are allowed would depend on the function.




More information about the Python-ideas mailing list