with open(config_file) as fd:
    conf = ConfigParser.ConfigParser()
conf.readfp(fd)
header = {}
for key in conf.options('structure'):
    start_idx, end_idx = [int(x) for x in conf.get('structure', key).split(',')
        ]
start_idx -= 1
strLength = end_idx - start_idx
header[key] = struct.unpack('%is' % strLength, data[start_idx:end_idx])
header[key] = [x.strip() for x in header[key]]
header[key] = [x.replace('\x00', '') for x in header[key]]
header = {k: v[0] for k, v in header.items()}
return header
Reading binary data in python