Octal number problem

Anna revanna at mn.rr.com
Thu Feb 20 03:50:57 CET 2003


On Thu, 20 Feb 2003 02:27:37 +0000, 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:
> 
>>>> int("0100")
> 100

Be careful of your quotes, however. Without the quotes, you'll get:

>>> int(0100)
64

which is probably not what you want.

Anna





More information about the Python-list mailing list