Steven D'Aprano added the comment:
The behaviour is correct. You have tripped over the ASCII representation of
bytes. In ASCII, 119 (or in hex, 0x77) is displayed as 'w'.
>>> b'\x77\x00\x00\x00'
b'w\x00\x00\x00'
--
nosy: +steven.daprano
resolution: -> not a bug
stage: -> resolved
New submission from Terje Myklebust :
>>> struct.pack("i", 119)
b'w\x00\x00\x00'
"w" in a binary value?
>>> struct.pack("I", 116)
b't\x00\x00\x00'
"t" in a binary value?
--
messages: 406150
nosy: terje.myklebust123
from struct import pack
pack(B, 1)
'\x01'
pack(BB, 0, 1)
'\x00\x01'
pack(BI, 0, 1)
'\x00\x00\x00\x00\x01\x00\x00\x00'
calcsize(BI)
8
calcsize(BB)
2
Why does an unsigned char suddenly become 4 bytes long when you
include an unsigned int in the format string? It's consistent
behaviour
[Alex Stapleton]
from struct import pack
pack(B, 1)
'\x01'
pack(BB, 0, 1)
'\x00\x01'
pack(BI, 0, 1)
'\x00\x00\x00\x00\x01\x00\x00\x00'
calcsize(BI)
8
calcsize(BB)
2
Why does an unsigned char suddenly become 4 bytes long when you
include an unsigned int in the format string?
Idiot.
On 11 Jan 2006, at 10:46, Alex Stapleton wrote:
from struct import pack
pack(B, 1)
'\x01'
pack(BB, 0, 1)
'\x00\x01'
pack(BI, 0, 1)
'\x00\x00\x00\x00\x01\x00\x00\x00'
calcsize(BI)
8
calcsize(BB)
2
Why does an unsigned char suddenly become 4 bytes long when you
include an