hex int and string
ben+python at benfinney.id.au
Fri Nov 27 10:22:38 CET 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
You either want it as an int, or you want it as a string. Which is it?
>>> foo = 'D3'
>>> int(foo, 16)
>>> int(foo, 16) == 0xD3
\ “Human reason is snatching everything to itself, leaving |
`\ nothing for faith.” —Saint Bernard, 1090–1153 |
More information about the Python-list