Python Gotcha with Octal Numbers

Clive Page cgp at le.ac.uk
Fri Feb 22 07:06:42 EST 2002


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.  :-)



More information about the Python-list mailing list