Unpacking from strings works:
>>> import struct
>>> struct.unpack('>h', 'ab')
(24930,)
>>> struct.unpack_from('>h', 'zabx', 1)
(24930,)
but if its a bytearray
:
>>> struct.unpack_from('>h', bytearray('zabx'), 1)
Traceback (most recent call last):
File "<ipython-input-4-d58338aafb82>", line 1, in <module>
struct.unpack_from('>h', bytearray('zabx'), 1)
TypeError: unpack_from() argument 1 must be string or read-only buffer, not bytearray
Which seems a little odd. What am I actually supposed to do about it? obviously I could:
>>> struct.unpack_from('>h', str(bytearray('zabx')), 1)
(24930,)
But i'm explicitly trying to avoid copying possibly large amounts of memory around.