Take this example:
i = 0x12345678
print(\"{:08x}\".format(i))
# shows 12345678
i = swap32(i)
print(\"{:08x}\".format(i))
# should print 78563412
From python 3.2 you can define function swap32() as the following:
def swap32(x):
return int.from_bytes(x.to_bytes(4, byteorder='little'), byteorder='big', signed=False)
It uses array of bytes to represent the value and reverses order of bytes by changing endianness during conversion back to integer.