On 02/11/2016 11:07 AM, Nick Coghlan wrote: > On 11 February 2016 at 19:59, Victor Stinner <victor.stin...@gmail.com> wrote: >> 2016-02-11 9:11 GMT+01:00 Georg Brandl <g.bra...@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. > > Given that str.format supports a thousands separator: > >>>> "{:,d}".format(100000000) > '100,000,000' > > it might be reasonable to permit "_" in place of "," in the format specifier. > > However, I'm not sure when you'd use it aside from code generation, > and you can already insert the thousands separator and then replace > "," with "_".
It would make "SI style" [0] numbers a little bit more straightforward to generate, since the order of operations wouldn't matter. Currently it's: "{:,}".format(1234.5678).replace(',', ' ').replace('.', ',') Also it would make numbers with decimal comma and dot as separator a bit easier to generate. Currently, that's (from PEP 378): format(n, "6,f").replace(",", "X").replace(".", ",").replace("X", ".") [0] https://en.wikipedia.org/wiki/Decimal_mark#Examples_of_use _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com