How to convert a "long in a string" to a "long"?

Klaus Alexander Seistrup klaus at seistrup.dk
Fri Nov 18 11:21:43 EST 2005


Carsten Haese wrote:

>> OK, this is what I want, so I tried
>> 
>> s = long("0xffffffffL")
>> ValueError: invalid literal for long(): 0xffffffffL
>> 
>> s = long("0xffffffff")
>> ValueError: invalid literal for long(): 0xffffffffL
>> 
>> What can I do? 
>> 
>> Thank you in advance.
>> Stefan
>
> Leave out the "0x" prefix and tell long() that you're using 
> base 16:
>
>>>> long("ffffffff", 16)
> 4294967295L

It's sufficient to tell long() that you're using base 16:

#v+

>>> long('0xffffL', 16)
65535L
>>> 

#v-

Cheers,

-- 
Klaus Alexander Seistrup
Copenhagen, Denmark
http://seistrup.dk/



More information about the Python-list mailing list