struct.Struct random access

castironpi castironpi at
Sat Aug 30 06:28:43 CEST 2008

On Aug 29, 10:30 pm, Tim Roberts <t... at> wrote:
> castironpi <castiro... at> wrote:
> >CMIIW correct me if I'm wrong, I don't think that pack_into returns a
> >value the way that pack does.
> Sorry, I was not aware that struct.pack_into and struct.unpack_from already
> existed (they were added in Python 2.5).  I thought you were proposing them
> as new additions.
> Because of that, the rest of my post doesn't make much sense.
> --
> Tim Roberts, t... at
> Providenza & Boekelheide, Inc.

I was a lot less enthusiastic too when I discovered
'PyObject_AsWriteBuffer'.  Nevertheless I think it could be
instructive as well as a benefit.  The ctypes conversion,
cast( buffer_p + offset ), is a bit of a kludge.  With the
introduction of 'namedtuple' type, I think it falls right in line with
the direction Python is going in.

It might suffice to merely expose the 'offset' member of the items in
the array of 'formatcode'.  Though, the addition of the dictionary to
lookup offsets by field name could offset the benefit somewhat.

More information about the Python-list mailing list