Octal number problem
gmduncan at netspace.net.au
Thu Feb 20 03:45:43 CET 2003
Raymond Hettinger wrote:
> [Gary Duncan]
>>Python has the quaint behaviour of interpreting
>>a numeric string with a leading zero as octal, a bit like C.
>>How does one disable this behaviour, ie get it to
>>treat such strings as a "normal" decimal number ?
> The int() function will assume base 10 and ignore the
> leading zero cue for octal:
Thanks Raymond - the secret is the quotes, as I've just noted
in a test.
I see :-
int (0100) yields 64, whereas as you point out
int ("0100") yields 100.
One of my Python books mentions int(N) and in an example
quotes N but doesn't say that it forces base-10
Ain't the WEB wonderful :) Post a question and get an answer before
you can make a cup of coffee.
- Gary (now a happy quoter )
> Raymond Hettinger
More information about the Python-list