Question about binary file reading
clp2 at rebertia.com
Thu Mar 5 00:15:28 CET 2009
On Wed, Mar 4, 2009 at 2:58 PM, vibgyorbits <bkajey at gmail.com> wrote:
> I'm writing a tool to do some binary file comparisons.
> I'm opening the file using
> # 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.
`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.
I have a blog:
More information about the Python-list