title: Python: access structure field through its name in a string
body: <p>In Scapy, I want to compare a number of header fields between any two packets <code>a</code> and <code>b</code>. This list of fields is predefined, say:</p>
  
  <pre><code>fieldsToCompare = ['tos', 'id', 'len', 'proto'] #IP header
  </code></pre>
  
  <p>Normally I would do it individually:</p>
  
  <pre><code>if a[IP].tos == b[IP].tos:
     ... do stuff...
  </code></pre>
  
  <p>Is there any way to access those packet fields from a list of strings including what each one of them is called? Like:</p>
  
  <pre><code>for field in fieldsToCompare:
      if a[IP].field == b[IP].field:
           ... do stuff...
  </code></pre>