[Python-Dev] an idea for improving struct.unpack api
Ilya Sandler
ilya at bluefir.net
Sat Jan 8 06:37:36 CET 2005
> How about making offset a standard integer, and change the signature to
> return tuple when it is used:
> item, offset = unpack(format, rec, offset) # Partial unpacking
Well, it would work well when unpack results are assigned to individual
vars:
x,y,offset=unpack( "ii", rec, offset)
but it gets more complicated if you have something like:
coords=unpack("10i", rec)
How would you pass/return offsets here? As an extra element in coords?
coords=unpack("10i", rec, offset)
offset=coords.pop()
But that would be counterintuitive and somewhat inconvinient..
Ilya
On Sat, 8 Jan 2005, Nick Coghlan wrote:
> Ilya Sandler wrote:
> > item=unpack( "IIII", rec, offset)
>
> How about making offset a standard integer, and change the signature to return a
> tuple when it is used:
>
> item = unpack(format, rec) # Full unpacking
> offset = 0
> item, offset = unpack(format, rec, offset) # Partial unpacking
>
> The second item in the returned tuple being the offset of the first byte after
> the end of the unpacked item.
>
> Cheers,
> Nick.
>
> --
> Nick Coghlan | ncoghlan at email.com | Brisbane, Australia
> ---------------------------------------------------------------
> http://boredomandlaziness.skystorm.net
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/ilya%40bluefir.net
>
More information about the Python-Dev
mailing list