Why is my struct.pack printing a string instead of a binary stream?
var = struct.pack('hhl3sf', 1, 2, 3, 'm6y', 2.7)
print repr(var)
The output is:
'\x01\x00\x02\x00\x03\x00\x00\x00m6y\x00\xcd\xcc,@'
Should the 'm6y' be printed as \x6d\x36\x79? And if not, how can I print it directly from pack as her or just plain binary? And why is the char @ print at the end? Thanks.
I tried converting all value to ascii and then print them in hex. And also running binascii.hexlify. Both of them works, but I'm wondering why pack is not doing this automatically. Thanks.
map(lambda c: ord(c), var)
map(lambda i: hex(i), map(lambda c: ord(c), var))
print 'Packed value : ', binascii.hexlify(var)