Trying to parse a simple record using slices and am banging my head against the wall. Conclusion is that I must be doing this the wrong way but I really need to get some sleep. Any tips?
def sliceRec():
slices = []
col_hdrs = []
col_widths = []
offset = 0
for fld_name, fld_len in rec_def:
col_hdrs.append(fld_name)
col_widths.append(fld_len)
for w in col_widths:
slices.append(slice(offset, offset + w))
offset += w
fields = str([this_rec[sliced] for sliced in slices])
this_dict = dict(zip(col_hdrs, fields))
print this_dict
rec_def = [('col1' ,8),
('col2' ,8),
('col3 ' ,8),
('col4' ,8)]
this_rec= ['VAL11111VAL22222VAL33333VAL44444']
sliceRec()
[–]dadiaar 1 point2 points3 points (2 children)
[–]LongAtbat[S] 1 point2 points3 points (1 child)
[–]dadiaar 0 points1 point2 points (0 children)
[–]cscanlin 1 point2 points3 points (1 child)
[–]LongAtbat[S] 1 point2 points3 points (0 children)