[Python-Dev] Lazy unpacking for struct module

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Jun 13 23:54:17 CEST 2011


Raymond Hettinger wrote:

> How would you describe the creation of a lazy result
> that keeps a reference to the underlying buffer?

I'd call it a view. There is plenty of precedence for this
kind of object in Python -- I gave a few examples before.

The distinguishing feature of ropes, as I understand the
term, is that you get a lazy object when you *combine* other
objects, e.g. concatenating strings.

That's not being asked for here -- there is only taking
apart going on, not putting together.

It's also different from the oft-rejected idea of lazy
string slicing, because extracting a field would give
you a separate object, e.g. an int or string, not a
reference to the original data object being unpacked.

So I really can't see what harm it could do, except for
maybe a tiny performance reduction in the case where you
extract all the fields, or refer to extracted fields
repeatedly.

Even if that turned out to be the case, and was considered
objectionable, it could still be useful to provide
view-oriented unpacking as an option.

-- 
Greg


More information about the Python-Dev mailing list