pack an integer into a string
gallium.arsenide at gmail.com
Sat Jul 25 02:14:59 CEST 2009
On Jul 24, 7:16 pm, superpollo <u... at example.net> wrote:
> thanks a lot, but [struct] does not work for large integers:
Since the struct module is designed specifically for C-style structs,
it's definitely not going to handle arbitrary-length integers on its
own. You could chop up your Python (long) integer into C-sized pieces
and then pack the pieces; but if you need to do that, the advantage of
using struct at all may be minimal or even completely gone.
> OTOH, using a higher [pickle] protocol:
If you are sure you are going to keep using the same version of
Python, then this could work. I would personally not depend on this
to keep working in future versions.
I'm not aware of any existing package that does what you want. Maybe
someone else does. How I personally would tackle your problem is to
write the whole thing from scratch (as you've done).
More information about the Python-list