Sarang Sarang - 1 year ago 134
Python Question

Error using struct.pack

I am trying to create packed binary data, using struct.pack() in python3.x

It is giving me the below error, but I am unable to understand.

packed1 = struct.pack('>i4', 7, 8)

errorTraceback (most recent call last)
<ipython-input-823-a27a6bc07ff4> in <module>()

----> 1 packed1 = struct.pack('>i4', 7, 8)

error: repeat count given without format specifier

Answer Source

The repeat count should be before the i

struct.pack('>4i', 7, 8, 3, 2)

Also you need 4 parameters not only 2

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download