[Python-Dev] PEP 515: Underscores in Numeric Literals (original) (raw)

Victor Stinner victor.stinner at gmail.com
Thu Feb 11 04:59:12 EST 2016


2016-02-11 9:11 GMT+01:00 Georg Brandl <g.brandl at gmx.net>:

On 02/11/2016 12:04 AM, Victor Stinner wrote:

It looks like the implementation https://bugs.python.org/issue26331 only changes the Python parser.

What about other functions converting strings to numbers at runtime like int(str) and float(str)? Paul also asked for Decimal(str). I added these as "Open Questions" to the PEP.

Ok nice. Now another question :-)

Would it be useful to add an option to repr(int) and repr(float), or a formatter to int.format() and float.float() to add an underscore for thousands. Currently, we have the "n" format which depends on the current LC_NUMERIC locale:

'{:n}'.format(1234) '1234' import locale; locale.setlocale(locale.LCALL, '') 'fr_FR.UTF-8' '{:n}'.format(1234) '1 234'

My idea:

(1234).repr(pep515=True) '1_234' (1234.0).repr(pep515=True) '1_234.0'

or maybe:

'{:pep515}'.format(1234) '1_234' '{:pep515}'.format(1234.0) '1_234.0'

I don't think that it would be a good idea to modify repr() default behaviour, it would likely break a lot of applications.

Victor



More information about the Python-Dev mailing list