I have a binary file that contains some text with a structure on a it. Here's a sample with some lines:
...
sCoilSelectMeas.aRxCoilSelectData[0].asList[0].lElementSelected = 1
sCoilSelectMeas.aRxCoilSelectData[0].asList[0].lMuxChannelConnected = 8
sRXSPEC.lGain = 1
sRXSPEC.asNucleusInfo[0].tNucleus = ""1H""
sRXSPEC.asNucleusInfo[0].lCoilSelectIndex = 0
...
I've parsed this structure into a Python OrderedDict as an intermediate step, using the following function:
from collections import OrderedDict
def parse_x(binfile):
result = OrderedDict()
with open(binfile, 'rb') as openfile:
rx = re.compile(b'(.*)\t = \t(.*)\n')
for line in openfile:
m = rx.match(line)
if m:
result[m.group(1).decode('utf-8')] = m.group(2).decode('utf-8')
return result
so that now I have said OrderedDict with the following:
...
('sCoilSelectMeas.aRxCoilSelectData[0].asList[0].lElementSelected', '1'),
('sCoilSelectMeas.aRxCoilSelectData[0].asList[0].lMuxChannelConnected', '8'),
('sRXSPEC.lGain', '1'),
('sRXSPEC.asNucleusInfo[0].tNucleus', '""1H""'),
('sRXSPEC.asNucleusInfo[0].lCoilSelectIndex', '0'),
...
How could I parse this OrderedDict into a Python object so that I could access fields as I would in the original structure? i.e.:
In[1]: sCoilSelectMeas.aRxCoilSelectData[0].asList[0].lElementSelected
Out[1]: 1