python 2.2 string conversion ?

Bengt Richter bokr at oz.net
Thu Jul 24 08:05:58 CEST 2003


On Thu, 24 Jul 2003 05:31:17 GMT, "ken" <kericks272 at earthlink.net> wrote:

>I've been looking for a solution to a string to long conversion problem that
>I've run into
>
>>>> x = 'e10ea210'
>>>> print x
>e10ea210
>>>> y=long(x)
>Traceback (most recent call last):
>  File "<pyshell#2>", line 1, in ?
>    y=long(x)
>ValueError: invalid literal for long(): e10ea210
>>>> x='0xe10ea210'
>>>> print x
>0xe10ea210
>>>> y=long(x)
>Traceback (most recent call last):
>  File "<pyshell#5>", line 1, in ?
>    y=long(x)
>ValueError: invalid literal for long(): 0xe10ea210
>>>> x="e10ea210"
>>>> y=long(x)
>Traceback (most recent call last):
>  File "<pyshell#7>", line 1, in ?
>    y=long(x)
>ValueError: invalid literal for long(): e10ea210
>>>> x="0xe10ea210"
>>>> y=long(x)
>Traceback (most recent call last):
>  File "<pyshell#9>", line 1, in ?
>    y=long(x)
>ValueError: invalid literal for long(): 0xe10ea210
>>>>
>
>What am I doing wrong?
>
Need to supply base if converting string that is not base 10

 >>> long('123')
 123L
 >>> long('0xe10ea210',16)
 3775832592L


Regards,
Bengt Richter




More information about the Python-list mailing list