pack an integer into a string
user at example.net
Fri Jul 24 19:16:07 EDT 2009
Piet van Oostrum wrote:
> You have the string wrong.
> But the correct one you get with:
> In : import struct
> In : number = 252509952
> In : struct.pack('>I', number)
> Out: '\x0f\x0c\xff\x00'
> (Please note that this is big endian)
thanks a lot, but it does not work for large integers:
>>> struct.pack('>I', number)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
OverflowError: long int too large to convert
More information about the Python-list