[Python-Dev] an idea for improving struct.unpack api (original) (raw)

Bob Ippolito bob at redivi.com
Thu Jan 6 20:38:56 CET 2005


On Jan 6, 2005, at 8:17, Michael Hudson wrote:

Ilya Sandler <ilya at bluefir.net> writes:

A problem:

The current struct.unpack api works well for unpacking C-structures where everything is usually unpacked at once, but it becomes inconvenient when unpacking binary files where things often have to be unpacked field by field. Then one has to keep track of offsets, slice the strings,call struct.calcsize(), etc... IMO (and E), struct.unpack is the primitive atop which something more sensible is built. I've certainly tried to build that more sensible thing at least once, but haven't ever got the point of believing what I had would be applicable to the general case... maybe it's time to write such a thing for the standard library.

This is my ctypes-like attempt at a high-level interface for struct.
It works well for me in macholib:
http://svn.red-bean.com/bob/py2app/trunk/src/macholib/ptypes.py

-bob



More information about the Python-Dev mailing list