hex int and string
Ben Finney
ben+python at benfinney.id.au
Fri Nov 27 04:22:38 EST 2009
luca72 <lucaberto at libero.it> writes:
> str = 'D3'
Be careful when choosing names. Here you have clobbered the existing
string type binding to the name ‘str’.
> and i need to trasform in 0xd3 type int and not type string how i can
> do this?
You already have the answer; you used it in your example below. I can
only assume you're wanting something additional; what is that?
> if i do hex(int(str,16) ) i obtain a string and this is not what i
> need.
You either want it as an int, or you want it as a string. Which is it?
>>> foo = 'D3'
>>> int(foo, 16)
211
>>> 0xD3
211
>>> int(foo, 16) == 0xD3
True
--
\ “Human reason is snatching everything to itself, leaving |
`\ nothing for faith.” —Saint Bernard, 1090–1153 |
_o__) |
Ben Finney
More information about the Python-list
mailing list