Issue 5782: ',' formatting with empty format type '' (PEP 378) (original) (raw)
PEP 378 says that the ',' format option applies to types 'd', 'e', 'f', 'g', 'E', 'G', '%' and 'F'. I think this should also be extended to include the empty type ''.
This only makes a difference for floats. For ints, '' is the same as 'd', but for floats '' is distinct. In 3.1 we get this behavior:
format(1.2, '010.2') '00000001.2' format(1.2, '010,.2') Traceback (most recent call last): File "", line 1, in ValueError: Cannot specify ',' with ''.
I think the second example should be valid.
Sounds good to me, too.
It looks as though the Decimal type already does this:
Python 3.1a2+ (py3k:71669:71684M, Apr 17 2009, 19:23:53) [GCC 4.0.1 (Apple Inc. build 5490)] on darwin Type "help", "copyright", "credits" or "license" for more information.
from decimal import Decimal format(Decimal('1.2'), '010.2') '00000001.2' format(Decimal('1.2'), '010,.2') '0,000,001.2'