title: Parsing one field of PCAP file into a column in Python
body: <p>I am currently work on a PCAP file and want to export of the one particular field(['TCP'].srcport) into a separate variable. The ['TCP'].srcport is not present for every row. it is present for the first 3 rows and not present for the remaining 3 row. The following is the code which I am using,</p>
  
  <pre><code>a = []
  l = 0
  for i in pcap_file:
      try :
          print l
          print(i['TCP'].srcport)
          a[l] = i['TCP'].srcport
          l = l+1
      except:
           print l
           print 'None'
           a[l] = 0
           l = l+1
           continue
  </code></pre>
  
  <p>The problem here is the ['TCP'].srcport is not present in all the rows of the PCAP file. I want to parse the value wherever it is available and when it is not available, I want to give a value as "None". I am able to print something as follows,</p>
  
  <pre><code>64
  64
  64
  None
  None
  None
  </code></pre>
  
  <p>But when I assign it to a variable, I am getting the following error,</p>
  
  <pre><code>--&gt; 13         a[l] = "
       14         l = l+1
       15         continue
  
  IndexError: list assignment index out of range
  </code></pre>
  
  <p>I would ideally want something like in a variable called l,</p>
  
  <p>l</p>
  
  <p>64
  64
  64
  None
  None
  None</p>
  
  <p>Can anybody help me in handling the exceptions and placing all the values into a  variable?</p>