At 01:12 PM 7/6/2005, Marcus Goldfish wrote:
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?

A file is a sequence of characters. That is what Python is showing you. Since 3 of them are not "graphic characters" Python displays their hexadecimal equivalents.. x19 translated to base 10 is 25. To ask Python to (in essence) cast a character to an integer you use the ord function. Ord('\x19') will give you integer 25.


Thanks!
Marcus
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Bob Gailer
mailto:[EMAIL PROTECTED]
510 558 3275 home
720 938 2625 cell

_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to