When I tried to run this same program on my computer and my school's server, I get these two different behaviors from struct.pack(...)
.
This is from my computer
Python 3.7.0 (default, Oct 9 2018, 10:31:47)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import struct
>>> struct.pack('HL',0,123456)
b'\x00\x00\x00\x00\x00\x00\x00\x00@\xe2\x01\x00\x00\x00\x00\x00'
This is from my school server
Python 3.7.0 (default, Aug 1 2018, 14:55:42)
[GCC 4.8.4] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> import struct
>>> struct.pack('HL',0,123)
b'\x00\x00\x00\x00\x00\x00\x00{'
As you can see, the length of the output is different on both systems, for reasons unrelated to Python version. Is there a way to coerce or force the output to be 8 or 16 bytes long? The HL
format is actually only 6 bytes long, but on the school server, it expands to be 8 bytes. On my local computer, 'HL' expands to 16 bytes for some reason.
This behavior is critical because I need to pass this function later on to struct.unpack(...)
which would require different length inputs on depending on the length of the output from struct.pack(...)
.