[New-bugs-announce] [issue2909] struct.Struct.unpack to return a namedtuple for easier attribute access

Aaron Gallagher report at bugs.python.org
Sun May 18 22:13:20 CEST 2008


New submission from Aaron Gallagher <habnabit at gmail.com>:

With the advent of collections.namedtuple, I thought that having a 
counterpart in the struct module would make having to deal with unpacked 
data much easier. Per suggestion, this extends the behavior of 
_struct.Struct rather than a separate NamedStruct class.

The regexp might not be immediately obvious as to what the format 
required is. The format string is represented like this: 
"attribute_name1(attribute_format) attribute_name2(attribute_format2)" 
and so on. Formats given in parentheses without an attribute name are 
allowed, so that byte order and pad bytes can be specified. For example: 
"(!) x1(h) x2(h) (2x) y1(h) y2(h)"

Suggestions and criticism are welcome. I think it would simplify using 
the struct module a lot to be able to have named attributes like this.

----------
components: Library (Lib)
files: named-struct.patch
keywords: patch
messages: 67038
nosy: habnabit
severity: normal
status: open
title: struct.Struct.unpack to return a namedtuple for easier attribute access
versions: Python 3.0
Added file: http://bugs.python.org/file10368/named-struct.patch

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2909>
__________________________________


More information about the New-bugs-announce mailing list