[Tutor] file io: reading an int32 at the end of a file?

Marcus Goldfish magoldfish at gmail.com
Wed Jul 6 22:12:59 CEST 2005


Hi,

I have a file format that ends in a 4-byte (int32) number.  I would
like to read this value in python on a WinXP machine with something
like:

fname = 'somefile'
f = open(fname, 'rb')
f.seek(-4,2)
offset = f.read()

... but this doesn't seem to work.  The value that Python returns is:

   '@\x19\x01\x00'

but I know from similar code in Matlab that the correct sequence is:

   64 25 1 0

Can someone point out my error?

Thanks!
Marcus


More information about the Tutor mailing list