[Python-Dev] Lazy unpacking for struct module

Nick Coghlan ncoghlan at gmail.com
Mon Jun 13 07:34:33 CEST 2011


On Mon, Jun 13, 2011 at 6:31 AM, Terry Reedy <tjreedy at udel.edu> wrote:
> With just 1 or 2 filter fields, and very many other fields, I would just
> unpack everything, including the filter field. I expect the extra time to do
> that would be comparalbe to the extra time to combine. It certainly would
> make your code easier. I suspect you could write a function to create the
> filter field only format by field number from the everything format.

Indeed, while the "filter format" part makes sense to me, the decision
to go with field combination rather than just extracting the filter
fields a second time isn't such an obvious improvement.

OTOH, it also seems like this is something that could be published as
a cookbook recipe that generated the appropriate filtered formats on
the fly from an existing struct definition. So given format "a b c d
e", it could either extract each field individually, or else be asked
to generate specific formats and their complements (e.g, asking for
the 2nd and 3rd field could return a 2-tuple of formats "x b c x x"
and "a x x c d e").

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-Dev mailing list