I have the following code to pack the dictionary into a struct …
>>> this = bytearray(2)
>>> this[0] = 100
>>> this[1] = 150
>>> bool = True
>>> str = 'new'
>>> dct = {'bt_arr': this, 'string':str, 'boolean': bool}
>>> print dct
{'bt_arr': bytearray(b'd\x96'), 'boolean': True, 'string': 'new'}
val = struct.pack ('!' + 'B' +'B' + 'B'*3 + '?', dct['bt_arr'][0], dct['bt_arr'][1],dct['string'][0:3], dct['boolean'])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
struct.error: pack requires exactly 6 arguments
can you kindly let me know what I’m doing wrong in the above code….
I want to unpack it in a similar fashion….
Thanks to
martineauandeumiroI got this solution, please let me know if there is a better solution