[Tutor] Covert numbers to hex fails

Tony Meyer tameyer at ihug.co.nz
Wed May 25 05:09:10 CEST 2005


> FAILS
> ----------
> >>> value = 1234567890
> >>> hexoutput = hex('%d' % (value))
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: hex() argument can't be converted to hex

Just don't convert the number to a string, e.g:

>>> value = 1234567890
>>> hexoutput = hex(value)
>>> hexoutput
'0x499602d2'

=Tony.Meyer



More information about the Tutor mailing list