>>>>> superpollo <[email protected]> (s) wrote:
>s> is there a pythonic and synthetic way (maybe some standard module) to
>s> "pack" an integer (maybe a *VERY* big one) into a string? like this:
>>>>> number = 252509952
>>>>> hex(number)
>s> '0xf0cff00'
>>>>>
>s> so i would like a string like '\xf0\xcf\xf0\x00'
You have the string wrong.
But the correct one you get with:
In [67]: import struct
In [68]: number = 252509952
In [69]: struct.pack('>I', number)
Out[69]: '\x0f\x0c\xff\x00'
(Please note that this is big endian)
--
Piet van Oostrum <[email protected]>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: [email protected]
--
http://mail.python.org/mailman/listinfo/python-list