Swap the main and alternative proposals.

Also refer to each by their original names (Proposal I and Proposal II).
Explain Guido's issue with Proposal II.
This commit is contained in:
Raymond Hettinger 2009-03-17 00:06:05 +00:00
parent ae992c1d06
commit 3eac76d6dc
1 changed files with 65 additions and 59 deletions

View File

@ -44,46 +44,45 @@ task easier for many users.
.. _`Babel`: http://babel.edgewall.org/
Main Proposal (from Eric Smith)
===============================
Main Proposal (from Nick Coghlan, originally called Proposal I)
===============================================================
Make both the thousands separator and decimal separator user
specifiable but not locale aware. For simplicity, limit the
choices to a COMMA, DOT, SPACE, APOSTROPHE or UNDERSCORE.
The SPACE can be either U+0020 or U+00A0.
A comma will be added to the format() specifier mini-language::
Whenever a separator is followed by a precision, it is a
decimal separator and an optional separator preceding it is a
thousands separator. When the precision is absent, a lone
specifier means a thousands separator::
[[fill]align][sign][#][0][width][,][.precision][type]
[[fill]align][sign][#][0][width][tsep][dsep precision]][type]
The ',' option indicates that commas should be included in the
output as a thousands separator. As with locales which do not
use a period as the decimal point, locales which use a
different convention for digit separation will need to use the
locale module to obtain appropriate formatting.
Examples::
The proposal works well with floats, ints, and decimals.
It also allows easy substitution for other separators.
For example::
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'
format(1234, "8_d") --> ' 1_234'
format(n, "6,d").replace(",", "_")
This proposal meets mosts needs, but it comes at the expense
of taking a bit more effort to parse. Not every possible
convention is covered, but at least one of the options (spaces
or underscores) should be readable, understandable, and useful
to folks from many diverse backgrounds.
This technique is completely general but it is awkward in the
one case where the commas and periods need to be swapped::
As shown in the examples, the *width* argument means the total
length including the thousands separators and decimal separators.
format(n, "6,f").replace(",", "X").replace(".", ",").replace("X", ".")
No change is proposed for the locale module.
The *width* argument means the total length including the commas
and decimal point::
The thousands separator is defined as shown above for types
'd', 'e', 'f', 'g', '%', 'E', 'G' and 'F'. To allow future
extensions, it is undefined for other types: binary, octal,
hex, character, etc.
format(1234, "08,d") --> '0001,234'
format(1234.5, "08,.1f") --> '01,234.5'
The ',' option is defined as shown above for types 'd', 'e',
'f', 'g', 'E', 'G', '%' and 'F'. To allow future extensions, it is
undefined for other types: binary, octal, hex, character,
etc.
This proposal has the virtue of being simpler than the alternative
proposal but is much less flexible and meets the needs of fewer
users right out of the box. It is expected that some other
solution will arise for specifying alternative separators.
Current Version of the Mini-Language
@ -143,44 +142,51 @@ specifiers like::
.. _`COBOL`: http://en.wikipedia.org/wiki/Cobol#Syntactic_features
Alternative Proposal (from Nick Coghlan)
========================================
Alternative Proposal (from Eric Smith, originally called Proposal II)
=====================================================================
A comma will be added to the format() specifier mini-language::
Make both the thousands separator and decimal separator user
specifiable but not locale aware. For simplicity, limit the
choices to a COMMA, DOT, SPACE, APOSTROPHE or UNDERSCORE.
The SPACE can be either U+0020 or U+00A0.
[[fill]align][sign][#][0][width][,][.precision][type]
Whenever a separator is followed by a precision, it is a
decimal separator and an optional separator preceding it is a
thousands separator. When the precision is absent, a lone
specifier means a thousands separator::
The ',' option indicates that commas should be included in the
output as a thousands separator. As with locales which do not
use a period as the decimal point, locales which use a
different convention for digit separation will need to use the
locale module to obtain appropriate formatting.
[[fill]align][sign][#][0][width][tsep][dsep precision]][type]
The proposal works well with floats, ints, and decimals.
It also allows easy substitution for other separators.
For example::
Examples::
format(n, "6,d").replace(",", "_")
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'
format(1234, "8_d") --> ' 1_234'
This technique is completely general but it is awkward in the
one case where the commas and periods need to be swapped::
This proposal meets mosts needs, but it comes at the expense
of taking a bit more effort to parse. Not every possible
convention is covered, but at least one of the options (spaces
or underscores) should be readable, understandable, and useful
to folks from many diverse backgrounds.
format(n, "6,f").replace(",", "X").replace(".", ",").replace("X", ".")
As shown in the examples, the *width* argument means the total
length including the thousands separators and decimal separators.
The *width* argument means the total length including the commas
and decimal point::
No change is proposed for the locale module.
format(1234, "08,d") --> '0001,234'
format(1234.5, "08,.1f") --> '01,234.5'
The thousands separator is defined as shown above for types
'd', 'e', 'f', 'g', '%', 'E', 'G' and 'F'. To allow future
extensions, it is undefined for other types: binary, octal,
hex, character, etc.
The ',' option is defined as shown above for types 'd', 'e',
'f', 'g', 'E', 'G', '%' and 'F'. To allow future extensions, it is
undefined for other types: binary, octal, hex, character,
etc.
This alternative proposal has the virtue of being simpler
than the main proposal but is much less flexible and meets
the needs of fewer users right out of the box.
The drawback to this alternative proposal is the difficulty
of mentally parsing whether a single separator is a thousands
separator or decimal separator. Perhaps it is too arcane
to link the decimal separator with the precision specifier.
Commentary