string.atoi and string.atol broken?

Mike Moum DoubleMPi at Netscape.com
Tue Jan 25 18:23:16 EST 2005


I think there may be a bug in string.atoi and string.atol.  Here's some 
output from idle.

> Python 2.3.4 (#2, Jan  5 2005, 08:24:51) 
> [GCC 3.3.5 (Debian 1:3.3.5-5)] on linux2
> Type "copyright", "credits" or "license()" for more information.
> 
>     ****************************************************************
>     Personal firewall software may warn about the connection IDLE
>     makes to its subprocess using this computer's internal loopback
>     interface.  This connection is not visible on any external
>     interface and no data is sent to or received from the Internet.
>     ****************************************************************
>     
> IDLE 1.0.4      
>>>> import string as s
>>>> s.atoi('2',3)
> 2
>>>> s.atoi('4',3)
> 
> Traceback (most recent call last):
>   File "<pyshell#2>", line 1, in -toplevel-
>     s.atoi('4',3)
>   File "/usr/lib/python2.3/string.py", line 220, in atoi
>     return _int(s, base)
> ValueError: invalid literal for int(): 4
>>>> s.atoi('12',11)
> 13
>>>> s.atoi('13',4)
> 7
>>>> s.atoi('12',4)
> 6
>>>> s.atoi('8',4)
> 
> Traceback (most recent call last):
>   File "<pyshell#6>", line 1, in -toplevel-
>     s.atoi('8',4)
>   File "/usr/lib/python2.3/string.py", line 220, in atoi
>     return _int(s, base)
> ValueError: invalid literal for int(): 8
>>>> 

s.atoi('4',3) should result in 11

s.atoi('13',4) should result in 31

s.atoi('12',4) should result in 30

s.atoi('8',4) is legitimate, but it generates an error.

Is this a bug, or am I missing something obvious?

TIA,
Mike




More information about the Python-list mailing list