struct.unpack will unpack data into a tuple. Is there an equivalent that will store data into a dict instead?
In my particular problem, I am dealing with a fixed-width binary format. I want to be able, in one fell swoop, to unpack and store the values in a dict (currently I manually walk through the list and assign dict values)
The
structdocumentation shows an example of unpacking directly into anamedtuple. You can combine this withnamedtuple._asdict()to get your one swell foop:If it matters, note that in Python 2.7
_asdict()returns anOrderedDict…