Question about binary file reading

Rhodri James rhodri at
Thu Mar 5 00:19:07 CET 2009

On Wed, 04 Mar 2009 22:58:38 -0000, vibgyorbits <bkajey at> 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.

Your bytes are being interpreted as characters when you print the buffer,  
and the chance of them being meaningful text is probably small.  Try the  

for b in x:
     print hex(ord(b))

Does that look more like what you were expecting?

Rhodri James *-* Wildebeeste Herder to the Masses

More information about the Python-list mailing list