Extending struct.unpack to produce nested tuples

I posted this to c.l.py the other day but didn't get any replies, so I thought I might see how it fares on python-dev. It's just an idea I had earlier this week. I'll attempt a patch if the response is positive. --- I was wondering if there would be any interest in extending the struct.unpack format notation to be able to express groups of data with parenthesis. For example:
Use Case: I have a program written in C that contains a bunch of aggregate data structures (arrays of structs, structs containing arrays, etc.) and I'm transmitting these structures over a socket connection to a Python program that then unpacks the data using the struct module. Problem is that I have to unpack the incoming data as a flat sequence of data elements, and then repartition the sequence into nested sequences to better reflect how the data is structured in the C program. It would be more convenient to express these groupings as I'm unpacking the raw data. I'm sure there are plenty of other use cases for such a feature. Matthew Barnes

This is a reasonable suggestion. You should also be able to write things like '4(ii)' which would be equivalent to '(ii)(ii)(ii)(ii)'. Please use SourceForge to upload a patch. Without a patch nobody is going to be interested though, I suspect, so don't wait for someone else to implement this. --Guido van Rossum (home page: http://www.python.org/~guido/)

An alternative would be to teach the C program to write the data in pickle or marshal format... :-) Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | A citizen of NewZealandCorp, a | Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. | greg@cosc.canterbury.ac.nz +--------------------------------------+

This is a reasonable suggestion. You should also be able to write things like '4(ii)' which would be equivalent to '(ii)(ii)(ii)(ii)'. Please use SourceForge to upload a patch. Without a patch nobody is going to be interested though, I suspect, so don't wait for someone else to implement this. --Guido van Rossum (home page: http://www.python.org/~guido/)

An alternative would be to teach the C program to write the data in pickle or marshal format... :-) Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | A citizen of NewZealandCorp, a | Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. | greg@cosc.canterbury.ac.nz +--------------------------------------+
participants (3)
-
Greg Ewing
-
Guido van Rossum
-
Matthew F. Barnes