[Python-Dev] PEP 515: Underscores in Numeric Literals

Paul Moore p.f.moore at gmail.com
Thu Feb 11 04:10:35 EST 2016


On 10 February 2016 at 23:14, Steven D'Aprano <steve at pearwood.info> wrote:
> On Wed, Feb 10, 2016 at 10:53:09PM +0000, Paul Moore wrote:
>> On 10 February 2016 at 22:20, Georg Brandl <g.brandl at gmx.net> wrote:
>> > This came up in python-ideas, and has met mostly positive comments,
>> > although the exact syntax rules are up for discussion.
>>
>> +1 on the PEP. Is there any value in allowing underscores in strings
>> passed to the Decimal constructor as well? The same sorts of
>> justifications would seem to apply. It's perfectly arguable that the
>> change for Decimal would be so rarely used as to not be worth it,
>> though, so I don't mind either way in practice.
>
> Let's delay making any change to string conversions for now, and that
> includes Decimal. We can also do this:
>
> Decimal("123_456_789.00000_12345_67890".replace("_", ""))
>
> for those who absolutely must include underscores in their numeric
> strings. The big win is for numeric literals, not numeric string
> conversions.

Good point. Maybe add this as an example in the PEP to explain why
conversions are excluded. But I did only mean the Decimal constructor,
which I think of more as a "decimal literal" - whereas int() and
float() are (in my mind at least) conversion functions and as such
should not be coupled to literal format (for example, 0x0001 notation
isn't supported by int())

Paul


More information about the Python-Dev mailing list