struct.pack returns packed result from input value.
In [19]: pack("i",4)
Out[19]: '\x04\x00\x00\x00'
I'm trying to printout the packed result as follows:
val = pack("i", 4)
print "%d" % int(val[0])
However, I got ValueError:
ValueError: invalid literal for int() with base 10: '\x04'
How can I print the packed value?
>>> import struct
>>> print struct.unpack("i", struct.pack("i",4))[0]
4