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

Steven D'Aprano steve at REMOVETHIScyber.com.au
Fri Nov 18 22:46:23 EST 2005


On Fri, 18 Nov 2005 11:10:06 -0500, Carsten Haese wrote:

>> 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


Or leave the prefix in, and tell Python to use the prefix to predict the
base:

py> long("0xffffffffL", 0)
4294967295L



-- 
Steven.




More information about the Python-list mailing list