Numeric literal syntax (was: Py 2.6 changes)

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Tue Sep 2 02:10:51 EDT 2008


On Tue, 02 Sep 2008 11:13:27 +1000, Ben Finney wrote:

> bearophileHUGS at lycos.com writes:
> 
>> For Python 2.7/3.1 I'd now like to write a PEP regarding the
>> underscores into the number literals, like: 0b_0101_1111, 268_435_456
>> etc.
> 
> +1 on such a capability.
> 
> -1 on underscore as the separator.
> 
> When you proposed this last year, the counter-proposal was made
> <URL:http://groups.google.com/group/comp.lang.python/
msg/18123d100bba63b8?dmode=source>
> to instead use white space for the separator, exactly as one can now do
> with string literals.
> 
> I don't see any good reason (other than your familiarity with the D
> language) to use underscores for this purpose, and much more reason
> (readability, consistency, fewer arbitrary differences in syntax,
> perhaps simpler implementation) to use whitespace just as with string
> literals.

At the risk of bike-shedding, I think that allowing arbitrary whitespace 
between string literals is fine, because it aids readability to write 
this:

do_something(
    "first part of the string"
    "another part of the string"
    "yet more of the string"
    "and a bit more"
    "and so on..."
    )
    
but I'm not sure that it is desirable to allow this:

do_something(
    142325
    93.8012
    7113
    )


-1/2 on arbitrary whitespace, +1/2 on a single space, and +0 on 
underscores. If semi-colons didn't already have a use, I'd propose using 
them to break up numeric literals:

14;232;593.801;271;13



-- 
Steven



More information about the Python-list mailing list