Python Gotcha with Octal Numbers

phil hunt philh at comuno.freeserve.co.uk
Fri Feb 22 15:58:05 CET 2002


On 22 Feb 2002 04:06:42 -0800, Clive Page <cgp at le.ac.uk> wrote:
>Philip Swartzleonard <starx at pacbell.net> wrote in message news:<Xns91B6DFD6A36CDRASXnewsDFE1 at 130.133.1.4>...
>> 
>> Steve has mentioned that UNIX people are used to it... i think it's a 
>> little deeper than that, b'cause as far as i know, _every_ programming 
>> language that has ever supported octal does it this way...
>
>Not quite all of them.  Fortran (at least since Fortran90) allows the
>forms O"01234" or O'1234' i.e. an upper-case O and a quoted string of
>digits (but they are only allowed in data statements, unfortunately).
>
>Prior to Fortran90 there was no _standard_ way of expressing octal
>constants, but lots of vendors had their own extensions.  But I don't
>recall ever coming across anything as error-prone as the C notation
>with a leading zero.  Fortran is a much safer language than C; I
>recommend it as the nearest thing to a compiled form of Python.  :-)

I like the way Smalltalk does it: BrN

Where B is a base, 2 to 36, and N is a number in that base, e.g:

2r11110000, 8r377, 16rFF, etc.

-- 
===== Philip Hunt ===== philh at comuno.freeserve.co.uk =====
Herbivore, a zero-effort email encryption system. Details at:
<http://www.vision25.demon.co.uk/oss/herbivore/intro.html>






More information about the Python-list mailing list