On Tue, 2005-05-24 at 22:56 -0400, Tom Tucker wrote:
> Good evening!  I am trying to pass a number variable and have it
> converted to hex.  Any recommendations on how to achieve this?  Thank
> you.
> 
> 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
> >>> 
> 
> 
> 
> WORKS
> -------------
> >>> hexoutput = hex(1234567890)
> >>> print hexoutput
> 0x499602d2
> >>>
Try one of those:
        '%x' % value # Will output the hex value without the leading 0x
        hex(value)   # Leading 0x will be printed

Ziyad.
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to