Numeric literals in other than base 10 - was Annoying octal notation

bartc bartc at freeuk.com
Sun Aug 23 11:57:57 EDT 2009


<garabik-news-2005-05 at kassiopeia.juls.savba.sk> wrote in message 
news:h6r4fb$18a$1 at aioe.org...
> In comp.lang.python James Harris <james.harris.1 at googlemail.com> wrote:
>> On 22 Aug, 10:27, David <71da... at libero.it> wrote:
>
> ...
>>>
>>> What about 2_1011, 8_7621, 16_c26h or 2;1011, 8;7621, 16;c26h ?
>>
>> They look good - which is important. The trouble (for me) is that I
>> want the notation for a new programming language and already use these
>> characters. I have underscore as an optional separator for groups of
>> digits - 123000 and 123_000 mean the same.
>
> Why not just use the space? 123 000 looks better than 123_000, and
> is not syntactically ambiguous (at least in python).

If the purpose is to allow "_" to introduce a non-base ten literal, using 
this to enter a hexadecimal number might result in:

16_1234 ABCD

I'd say that that was ambiguous (depending on whether a name can follow a 
number; if you have a operator called ABCD, then that would be a problem). 
Unless each block of digits used it's own base:

16_1234 16_ABCD


> And as it
> already works for string literals, it could be applied to numbers, too…

String literals are conveniently surround by quotes, so they're a bit easier 
to recognise.

-- 
Bart 




More information about the Python-list mailing list