This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ',' formatting with empty format type '' (PEP 378)
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.1, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: eric.smith Nosy List: eric.smith, mark.dickinson, rhettinger
Priority: normal Keywords: easy

Created on 2009-04-17 14:38 by eric.smith, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg86075 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2009-04-17 14:38
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 "<stdin>", line 1, in <module>
ValueError: Cannot specify ',' with ''.

I think the second example should be valid.
msg86079 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2009-04-17 18:27
I concur.
msg86080 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-04-17 18:33
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'
msg86081 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2009-04-17 18:35
I updated the PEP in r71686. I'll fix the code and add a test after I
backport the entire thing to 2.7.
msg86306 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2009-04-22 17:04
Checked in to trunk in r71802 and py3k in r71804.
History
Date User Action Args
2022-04-11 14:56:47adminsetgithub: 50032
2009-04-22 17:04:47eric.smithsetstatus: open -> closed
resolution: fixed
messages: + msg86306

versions: + Python 2.7
2009-04-17 18:35:47eric.smithsetmessages: + msg86081
2009-04-17 18:33:14mark.dickinsonsetmessages: + msg86080
2009-04-17 18:27:46rhettingersetmessages: + msg86079
2009-04-17 14:38:02eric.smithcreate