Python convert to little endian

I want to convert an integer value to a string of hex values, in little endian. For example, 5707435436569584000 would become '\x4a\xe2\x34\x4f\x4a\xe2\x34\x4f'.

All my googlefu is finding for me is hex[..] which gives me '0x4f34e24a4f34e180' which is not what I want.

I could probably manually split up that string and build the one I want but I'm hoping somone can point me to a better option.

asked Oct 30, 2012 at 15:01

2

You need to use the struct module:

>>> import struct
>>> struct.pack['

Chủ Đề