Question about binary file reading

Scott David Daniels Scott.Daniels at Acm.Org
Thu Mar 5 02:25:30 CET 2009

vibgyorbits wrote:
> I'm writing a tool to do some binary file comparisons.
> I'm opening the file using
>     fd=open(filename,'rb')
> > # Need to seek to 0x80 (hex 80th) location
> # Need to read just 8 bytes and get the result back in hex format.
>     print x
> This prints out garbage. I would like to know what am i missing here.
> Basically, I am trying to read
> 8 bytes from location 0x80 from a binary file called "filename"
> Any tips/inputs are welcome.

(1) Put some air into those assignments; spaces are free.
(2) You probably want something like this:
     import binascii
     fd = open(filename, 'rb')
     x =
     print binascii.hexlify(x)

--Scott David Daniels
Scott.Daniels at Acm.Org

More information about the Python-list mailing list