fork download
  1. x = 'AB ATEA 00040150'
  2.  
  3. def float_converter(value):
  4. return float('{0}.{1}'.format(value[:1], value[1:]))
  5.  
  6. alist = [('Code',0,2,None),
  7. ('Name',3,7,None),
  8. ('Value1',8,13,float_converter),
  9. ('Value2',13,16,float_converter)]
  10.  
  11. adict = {}
  12. for a, b, c, converter in alist:
  13. v = x[b:c]
  14. if converter:
  15. v = converter(v)
  16. adict[a] = v
  17.  
  18. print adict
  19.  
Success #stdin #stdout 0.01s 6356KB
stdin
Standard input is empty
stdout
{'Code': 'AB', 'Name': 'ATEA', 'Value1': 0.0040000000000000001, 'Value2': 1.5}