I tried some code from a python [tutorial for python struct][1]:
import struct
import binascii
values = (1, 'ab', 2.7)
s = struct.Struct('I 2s f')
packed_data = s.pack(*values)
and got error
Input In [4], in <cell line: 1>()
----> 1 s.pack(1, 'ab', 2.7)
error: argument for 's' must be a bytes object
Where is the problem?
[1] http://pymotw.com/2/struct/
>Solution :
The string must be a byte string, This should work
values = (1, bytes('ab','utf-8'), 2.7)
packed_data = s.pack(*values)