title: is there a way to avoid eval() to accomplish dynamic dispatch of a function specified in a list in python
body: <p>I have a list as defined here:</p>
  
  <pre><code>header_fields = [
  ['delim',0,4,'strip()'],
  ['qual',4,5,None],
  ['NLS_CODE',6,25,'strip()'],
  ['source_system_id',26,45,'strip()'],
  ['extract_name',46,65,'strip()'],
  ['extract_serial_number',66,85,'strip()'],
  ['file_counter',86,88,"lstrip('0')"],
  ['total_file_count',89,91,'strip()'],
  ['extract_run_date_time',92,126,'strip()'],
  ['from_date',127,161,'strip()'],
  ['thru_date',162,196,'strip()'],
  ['number_of_rows',197,216,'strip()'],
  ['data_recons1',217,246,'strip()'],
  ['data_recons2',247,276,'strip()'],
  ['data_recons3',277,306,'strip()']
  ]
  </code></pre>
  
  <p>element[1] and element[2] are used to parse a line called <code>header</code>
  I want to call element[3] for each element in <code>header_fields</code> like so:</p>
  
  <pre><code>for element in header_fields:
      a = header[element[1]:element[2]]
      if element[3] None:
          b = a
      else:
          b = eval('a.'+element[3])
  </code></pre>
  
  <p>Is there a way to restructure all of this to avoid eval? <code>ast.literal_eval('a.'+element[3])</code> throws 'malformed string'</p>