Octal number problem
Chad Netzer
cnetzer at mail.arc.nasa.gov
Wed Feb 19 23:03:27 EST 2003
On Wed, 2003-02-19 at 18:45, Gary Duncan wrote:
> Thanks Raymond - the secret is the quotes, as I've just noted
> in a test.
> int (0100) yields 64, whereas as you point out
>
> int ("0100") yields 100.
You can make int() raise an exception when converting an octal literal
(rather than a string), by giving an explicit base conversion parameter.
ie.:
>>> int('010', 10)
10
vs.
>>> int(010, 10)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: int() can't convert non-string with explicit base
--
Bay Area Python Interest Group - http://www.baypiggies.net/
Chad Netzer
(any opinion expressed is my own and not NASA's or my employer's)
More information about the Python-list
mailing list