[Python-Dev] Packing and unpacking integers

Josiah Carlson josiah.carlson at gmail.com
Sun Jul 6 03:52:26 CEST 2008


A few years ago (yes, it's been that long), I proposed adding a new
format code to struct that would pack integers as strings, similar to
the 's' format code.  In particular, struct.pack('>60G', v) would be a
60-byte big-endian unsigned integer as a string.  The feature request
is http://bugs.python.org/issue1023290 .

Shortly thereafter, it was decided that it wouldn't become a struct
format code, but instead would find itself as part of binhex.  Raymond
Hettinger was supposed to write the function a couple years ago for, I
believe, Python 2.4 .  It never happened.  It still hasn't happened
for Python 2.5 or 2.6 .

I believe there is still a need for packing integers as strings and
unpacking strings as integers, more specifically, offering to Python
an interface to _PyLong_FromByteArray() and _PyLong_AsByteArray().  I
would be happy to write the functionality and unittests this coming
week for 2.6 and 3.0 if I get the ok.  If not, I can write it for 2.7
and 3.1 .

 - Josiah


More information about the Python-Dev mailing list