struct unpack help?

Emile van Sebille emile at fenx.com
Thu Jul 11 10:27:21 EDT 2002


Scherer, Bill
> Here's a sample string of the struct:
>
> sampleStructString = "_782c1a08_p_void"
>
> I know that the struct defines only two unsigned shorts.  That
> would imply (to me, anyway) a format of 'HH'. But calcsize of
> that is 4, while my string is 16 bytes. So
>

If you know the expected results of the sample, you can pass in the
appropriate slice:

>>> struct.unpack('HH', s[1:5])
(14391, 25394)

>>> struct.unpack('II', s[1:9])
(1664235575L, 942694705L)

--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list