Patches item #847857, was opened at 2003-11-23 23:24 Message generated for change (Comment added) made by loewis You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=847857&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Modules Group: Python 2.5 >Status: Closed >Resolution: Out of Date Priority: 5 Private: No Submitted By: Matthew Barnes (mfbarnes) Assigned to: Raymond Hettinger (rhettinger) 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. ---------------------------------------------------------------------- >Comment By: Martin v. Löwis (loewis) Date: 2006-11-19 09:41 Message: Logged In: YES user_id=21627 Originator: NO This patch is now unfortunately out-of-date, since the struct module was heavily rewritten. Also, the original patch lacked documentation changes, and test cases. mfbarnes, if you are still interested in this feature, please submit a new patch, which hopefully gets reviewed faster this time. Rejecting this patch as out-of-date. ---------------------------------------------------------------------- Comment By: Fabian Bieler (fabe3k) Date: 2005-07-09 19:28 Message: Logged In: YES user_id=615150 I would like to see this patch applied to Python. This functionality would be very usefull for opening binary files with a given format. Is there a particular reason why this patch was not accepted? ---------------------------------------------------------------------- Comment By: Matthew Barnes (mfbarnes) Date: 2004-12-20 07:43 Message: Logged In: YES user_id=843448 I suggested this change on Python-Dev last year (http://mail.python.org/pipermail/python-dev/2003-November/040391.html). The use case I put forth at the time was as follows: 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. ---------------------------------------------------------------------- Comment By: Raymond Hettinger (rhettinger) Date: 2004-12-20 04:57 Message: Logged In: YES user_id=80475 What are the use cases to warrant this change? ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=847857&group_id=5470 _______________________________________________ Patches mailing list Patches@python.org http://mail.python.org/mailman/listinfo/patches