I am using module struct.unpack() to decode data from a binary file, so that I can use the value in a calculation.
I have been able to extract an integer value. >>>length = struct.unpack('i', '\x9c\x00\x00\x00') >>>length = int(length[0]) >>>print length 156 I want to be able to extract a string. I have tried, >>>first = struct.unpack('s', '\x02\x00') >>>first = str(first[0]) >>>print first Traceback (most recent call last): ...... error: unpack requires a string argument of length 1 and, >>>first = struct.unpack('cccc', '\x02\x00') >>>first = str(first[0]) >>>print first Traceback (most recent call last): ...... return o.unpack(s) error: unpack requires a string argument of length 4 My desired result would be the string '0200'. Actually, I would like to be able to invert the bytes to get '0002'.
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor