[Patches] [ python-Patches-847857 ] Extend struct.unpack to produce nested tuples

SourceForge.net noreply at sourceforge.net
Sun Nov 23 17:25:18 EST 2003


Patches item #847857, was opened at 2003-11-23 16:24
Message generated for change (Settings changed) made by mfbarnes
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=847857&group_id=5470

Category: Modules
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Matthew F. Barnes (mfbarnes)
Assigned to: Nobody/Anonymous (nobody)
>Summary: Extend struct.unpack to produce nested tuples

Initial Comment:
This patch extends the struct.unpack format notation to
be able to express groups of data with parentheses.

For example:

>>> data = struct.pack('iiii', 1, 2, 3, 4)
>>> struct.unpack('i(ii)i', data)
(1, (2, 3), 4)

Integral repeat counts can also be applied to groups.

>>> struct.unpack('2(ii)', data)
((1, 2), (3, 4))

In addition, struct.calcsize also handles parentheses
in format strings correctly.

>>> struct.calcsize('4(ii)')
32

No changes were made to struct.pack.  It still treats
parentheses as illegal format characters.

I have not yet updated any documentation or tests
associated with struct.calcsize or struct.unpack.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=847857&group_id=5470



More information about the Patches mailing list