Integer conversion

Bill C. Wong bcw at rave.ch
Sat Jun 15 09:10:45 EDT 2002


"Colin J. Williams" <cjw at sympatico.ca> wrote in message
news:3D0B3257.E8572AE5 at sympatico.ca...
> int(string, base) => integer
>
> For int('127',  8), I had expected this function to deliver 87.
>
> The example below correctly gives errors at the top and bottom of the
> range and
> for int('127', 10) delivers 127.  The other cases are not what I
> expected.

Python 2.2.1 (#34, Apr  9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> int( '127', 8 )
87
>>>


> I would appreciate any suggestions.
>
> Colin W.
>
> for b in range(2,38):
>   try:
>     print b, '[', int('127', b), ']'
>   except:
>     pass
>     print 'error'
>





More information about the Python-list mailing list