Python bug- struck.pack error

May I ask why this is the case?
Always fails to properly package the byte stream.

python bug.toe (5.4 KB)

Hi @ninjai,

in what way does it fail to properly package the byte stream?


Take look the debug information please, the bytes value is wrong.

Hi @ninjai,

if you check the length it returns 7 as expected and it’s correct when you unpack it again:

import struct

r = 255
g = 255
b = 255
x = 131
y = 1341

v = struct.pack('<BBBHH', r, g, b, x, y)

print(v, len(v))
# returns b'\xff\xff\xff\x83\x00=\x05' 7

# Unpack v back into integer values
r, g, b, x, y = struct.unpack('<BBBHH', v)

print(r, g, b, x, y)
# returns: 255 255 255 131 1341

Maybe it just looks wrong due to how the bytes are printed out?

EDIT: for clarification - in the printed result b'\xff\xff\xff\x83\x00=\x05' you indeed see 7 bytes:\xff,
\xff, \xff, \x83, \x00, =, and \x05. The = is actually the ascii charachter for \x3d which you can confirm when trying print('\x3d').


1 Like

Thanks a lot , Markus. :smile: