Python Gotcha with Octal Numbers
Philip Swartzleonard
starx at pacbell.net
Sat Feb 16 01:00:23 EST 2002
Christopher Saunter || Wed 13 Feb 2002 06:26:53a:
> Greetings All!
>
> I have been using Python now for arround a year, and have found it
> incredably easy to learn the language, primarily because things are
> very obvious cf other languages, and until the other day, I had never
> had a 'Gotcha' - a bug caused by me entering some code wrongly and not
> realising it.
>
> It all stems to this, I was assigning to numbers to variables:
>
> var1 = 1000
> var2 = 0100
> etc.
Just use spaces to balance, eg:
var1 = 1000
var2 = 200
var3 = 45
I do this all the time, in more complicated places...
glVertex3d( -(x_size + 1), -0.5, 0 )
glVertex3d( -(x_size + 1), 0.5, 0 )
glVertex3d( -(x_size + 1), 0, -0.5 )
glVertex3d( -(x_size + 1), 0, 0.5 )
Balancing negative signs and variable sizes =)
> [snip]
>
> Personally, I would like to see octal number entry migrated from 0---
> to something like 0o---. This would bring things more in line with
> the entry of hex numbers (0x---)
>
> I know it's only a minor thing, but it'd be nice if my numbers behaved
> as I expected...
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...
--
Philip Sw "Starweaver" [rasx] :: www.rubydragon.com
More information about the Python-list
mailing list