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 grouping_option ValueError: Cannot specify ',' with ...
Type: Stage: resolved
Components: Versions: Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: eric.smith Nosy List: Another One, eric.smith
Priority: normal Keywords:

Created on 2020-02-06 12:56 by Another One, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg361480 - (view) Author: Another One (Another One) Date: 2020-02-06 12:56
Example for binary representation:

>>> x = 123456
>>> print("{:,b}".format(x))
Traceback (most recent call last):
  File "<pyshell#261>", line 1, in <module>
    print("{:,b}".format(x))
ValueError: Cannot specify ',' with 'b'.

Why? Comma work only with decimals?

But '_' groups delimiter properly work with any integer representation including decimals, hexadecimals, binaries, octals, etc..
msg361482 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-02-06 13:46
No one thought it made sense to have a comma every 3 bits. Or for octal or hex, either.

Do you have some specific use case where it makes sense?
msg361490 - (view) Author: Another One (Another One) Date: 2020-02-06 15:12
Not for 3 bits, just for 4 bits, like this:
>>> print("{:_b}".format(123456))
1_1110_0010_0100_0000

And as I already said: "But '_' groups delimiter properly work with any integer representation including decimals, hexadecimals, binaries, octals, etc.." Not only for binaries.
Why comma delimiter is not?
Logic must be the same. Simple use the one procedure for '_' delimiter with permit comma as parameter, instead of two different logic.
msg361493 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-02-06 15:25
Well, you asked why commas only work with decimals and I told you.

Adding "_" would require a PEP. See PEP 378 if you want to write something similar for "_". I think it's a decent idea. You'll have to decide between 4 and 8 bits, and what to do with octal and hex.

But I'm going to close this issue, since it's about commas and non-base 10 representations. If you want to pursue underscores, the next step would be to discuss it on the python-ideas mailing list.
History
Date User Action Args
2022-04-11 14:59:26adminsetgithub: 83749
2020-02-06 15:25:54eric.smithsetstatus: open -> closed
messages: + msg361493

assignee: eric.smith
resolution: not a bug
stage: resolved
2020-02-06 15:12:23Another Onesetmessages: + msg361490
2020-02-06 13:46:24eric.smithsetnosy: + eric.smith
messages: + msg361482
2020-02-06 12:56:25Another Onecreate