Add Eric Smith's variant
This commit is contained in:
parent
524c658ed5
commit
189932bf8b
33
pep-0378.txt
33
pep-0378.txt
|
@ -150,6 +150,34 @@ length including the thousands separators and decimal separators.
|
||||||
No change is proposed for the locale module.
|
No change is proposed for the locale module.
|
||||||
|
|
||||||
|
|
||||||
|
Proposal III (from Eric Smith: like II but without the T)
|
||||||
|
=========================================================
|
||||||
|
|
||||||
|
In the second proposal, the *T* isn't strictly necessary.
|
||||||
|
In the context of an integer, an optional single specifier means
|
||||||
|
a thousands separator. In the context of a float, a single
|
||||||
|
specifier is a decimal separator while two specifiers are taken
|
||||||
|
as a thousands separator and a decimal separator::
|
||||||
|
|
||||||
|
[[fill]align][sign][#][0][width][tsep][dsep precision][type]
|
||||||
|
|
||||||
|
Examples::
|
||||||
|
|
||||||
|
format(1234, "8.1f") --> ' 1234.0'
|
||||||
|
format(1234, "8,1f") --> ' 1234,0'
|
||||||
|
format(1234, "8.,1f") --> ' 1.234,0'
|
||||||
|
format(1234, "8 ,f") --> ' 1 234,0'
|
||||||
|
format(1234, "8d") --> ' 1234'
|
||||||
|
format(1234, "8,d") --> ' 1,234'
|
||||||
|
|
||||||
|
This is a cleaner looking syntax but has the minor disadvantage of
|
||||||
|
using context to direct the translation. Whenever the separator
|
||||||
|
is followed by a precision, it decimal separator and a separator
|
||||||
|
preceding it is a thousands separator. When the precision is
|
||||||
|
absent, the context is integral and a lone specifier means
|
||||||
|
a thousands separator.
|
||||||
|
|
||||||
|
|
||||||
Other Ideas
|
Other Ideas
|
||||||
===========
|
===========
|
||||||
|
|
||||||
|
@ -160,8 +188,9 @@ Other Ideas
|
||||||
minwidth=32, pad='0')
|
minwidth=32, pad='0')
|
||||||
|
|
||||||
* Eric Smith would like the C version of the mini-language
|
* Eric Smith would like the C version of the mini-language
|
||||||
parser to be exposed. That would make it easier to write
|
parser to be exposed with hooks that would make it easier
|
||||||
custom __format__ methods.
|
to write custom __format__ methods. That way
|
||||||
|
Decimal.__format__ would not have to be written from scratch.
|
||||||
|
|
||||||
|
|
||||||
Copyright
|
Copyright
|
||||||
|
|
Loading…
Reference in New Issue