On Wed, Mar 4, 2009 at 2:58 PM, vibgyorbits <bka...@gmail.com> 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
>
> fd.seek(0x80)
>
> # Need to read just 8 bytes and get the result back in hex format.
> x=fd.read(8)
> print x
>
> This prints out garbage. I would like to know what am i missing here.

`print x` outputs the raw bytes in the bytestring `x` you just read,
which yes, generally looks like gibberish.
It doesn't magically convert it to hex format. Remember that
bytestrings could just as well contain ASCII in other situations,
which you certainly wouldn't want to see as hex. You'll have to
explicitly/manually do the conversion from bytes->hex.

Cheers,
Chris

-- 
I have a blog:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to