I need to send a message of bytes in Python and I need to convert an unsigned integer number to a byte array. How do you convert an integer value to an array of four bytes i
And for completeness: you can also use the array module:
>>> from array import array
>>> a = array('I', [100]) # note that 'I' and such are machine-dependent.
>>> a.tostring()
'\d\x00\x00\x00'
>>> a.byteswap()
>>> a.tostring()
'\x00\x00\x00\d'