I need to do a sort of reverse .format() to a string like
a = "01AA12345AB12345AABBCCDDEE".reverseformat({id:2d}{type:2s}{a:3d}{b:4s}{c:5d}{d:2s})
print a
>>>> {'id':1, 'type':'aa', 'a':'123', 'b':'45AB', 'c':'12345', 'd':'AA'}
I found this lib that makes almost what i need, the problem is that it gives me this result
msg = parse.parse("{id:2d}{type:3S}{n:5S}", "01D1dddffffffff")
print msg.named
>>>>{'type': 'D1dddfffffff', 'id': 1, 'n': 'f'}
and not
{'id':1, 'type':'D1d', 'n':'ddfffff'}
Does another lib/method/wathever that can "unpack" a string to a dict exists?
EDIT: Just for clarify, i already tryed the w and D format specification for string