Retrieving int from hex in a file.
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Mon Apr 28 06:29:12 EDT 2008
En Mon, 28 Apr 2008 07:14:51 -0300, Filipe Teixeira <filipe.tg at gmail.com> escribió:
> a in now a string full of hex representations in the form:
>
> a[6]='\x14'
> a[7]='\x20'
>
> I would like to convert these hex representations to int, but this
> (the most obvious way) doesn't seem to be working
>
>>>> q=a[6]
>>>> q
> '\x14'
>>>> int(q,16)
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> ValueError: invalid literal for int():
>>>>
Use ord(q)
py> help(ord)
Help on built-in function ord in module __builtin__:
ord(...)
ord(c) -> integer
Return the integer ordinal of a one-character string.
py>
--
Gabriel Genellina
More information about the Python-list
mailing list