Error with int()

Carel Fellinger cfelling at iae.nl
Sun Sep 30 05:56:01 CEST 2001


"Arturo Pérez Mulas" <arturo_perez at wanadoo.es> wrote:

> I am running python 2.1.1 under Windows XP BETA, and get the following
> error:

>>>> int('a')
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in ?
> ValueError: invalid literal for int(): a

Assuming you're after number conversion, add the radix to the call, like:

   >>> int('12', 8), int('12'), int('12', 16)
   (8, 12, 18)

Or use eval iff that string is trustworthy (so don't:), like:

   >>> eval('012'), eval('12'), eval('0x12')
   (8, 12, 18)

-- 
groetjes, carel



More information about the Python-list mailing list