Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Argument for struct packing must be bytes?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading