[issue42914] pprint numbers with underscore

Stéphane Blondon report at bugs.python.org
Sun Mar 14 18:42:53 EDT 2021


Stéphane Blondon <stephane.blondon at gmail.com> added the comment:

Thank you Felipe for the news! :)
I have committed a PR about this issue.

Two remarks:
- I changed the proposed implementation from 'format(integer, '_d')' to '{:_d}.format(integer)' because the first way raised an exception. (The `format` function was not defined.)
- I thought about adding the same behavior for float too but I didn't add it because the '_f' type uses a precision of 6 digits after the decimal point for float. So it's possible some precision would be lost with the pprint() call. It could mislead users more than helping them with the readability of the '_'. A precision value can be added but I'm not sure it's a good idea. based on [1]

As requested, there is a new parameter to disable this new behavior ('underscore_numbers').


1: https://docs.python.org/3/library/string.html#format-specification-mini-language

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42914>
_______________________________________


More information about the Python-bugs-list mailing list