Retrieving int from hex in a file.

Filipe Teixeira filipe.tg at gmail.com
Mon Apr 28 06:14:51 EDT 2008


Hi.

I have to open a binary file from an old computer and recover the
information stored (or at least try to). I use:

f=open('file.bin','rb')
a=f.read()
f.close()

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():
>>>

How can I do this?

Thanks



More information about the Python-list mailing list