title: Python: Attribute Error(NoneType object has no attribute split)
body: <p>I am trying to make some approximations discard.</p>
  
  <p>The function given below is throwing attribute error. What might be the issue? Kindly help me if possible.</p>
  
  <pre><code>def calculate_tps(filename,identity):
    ##command='tshark -r %s -R -T pdml diameter'
    first_time = None
    last_time=None
    tshark='tshark -r %s -R \'(diameter.Destination-Host==%s)&amp;&amp; (diameter.CC-Request-Type==3)\' -T pdml'% (filename,identity)
    time = None
    req = 0
    for line in os.popen(tshark, 'r'):
      m=pattern.search(line)    
      if m:
        #print m.group(1)
        if m.group(1) == 'timestamp':
      time=m.group(2)
      if not first_time:
        first_time=time
        elif m.group(1) == 'diameter.Session-Id':
          req +=1 
      if(req % 100) ==0:
        print 'processed 1000 requests req number %s ' % req
  
    # making some approximations discard ms 
    first = long(first_time.split('.').pop(0))
    last =  long(time.split('.').pop(0))
    time_elapsed = first -last
    print "%s requests in %s seconds, tps = %s " % ( req, time_elapsed, req/time_elapsed)   
  </code></pre>
  
  <p>Here is the full code. I am trying to calculate number of request per second using tshark. </p>
  
  <pre><code>#!/usr/bin/python
  import re
  import sys
  import commands
  
      import os
      import time
  
  
      pattern = re.compile('&lt;field name="(timestamp|diameter.Session-Id)".*value="([^"]+)')
  
  
      from optparse import OptionParser
      def parse_options():
        parser = OptionParser()
       # parser.add_option("-f", "--file", dest="filename",
       #                 help="input pcap file", metavar="FILE")
        parser.add_option("-i", "--identity", dest="identity",
                        help="diameter identity to filter on", metavar="IDENTITY")
  
        opts, args = parser.parse_args()
        return opts, args
  
      def calculate_tps(filename,identity):
        ##command='tshark -r %s -R -T pdml diameter'
        first_time = None
        last_time=None
        tshark='tshark -r %s -R \'(diameter.Destination-Host==%s)&amp;&amp; (diameter.CC-Request-Type==3)\' -T pdml'% (filename,identity)
        time = None
        req = 0
        for line in os.popen(tshark, 'r'):
          m=pattern.search(line)    
          if m:
            #print m.group(1)
            if m.group(1) == 'timestamp':
          time=m.group(2)
          print 'time is %s' % time
          if not first_time:
            first_time=time
            prin
            elif m.group(1) == 'diameter.Session-Id':
              req +=1 
          if(req % 100) ==0:
            print 'processed 1000 requests req number %s ' % req
  
        # making some approximations discard ms 
        first = long(first_time.split('.').pop(0))
        last =  long(time.split('.').pop(0))
        time_elapsed = first -last
        print "%s requests in %s seconds, tps = %s " % ( req, time_elapsed,
        req/time_elapsed)       
  
      def main():
        global options
        options, args = parse_options()
        if len(args) &lt; 1:
          print &gt;&gt;sys.stderr, "missing pcap file.Please specify the pcap"
          sys.exit(1)   
        #print options.identity  
  
  
  
        start_time = time.time()
        calculate_tps(args.pop(0), options.identity) 
        end_time = time.time()
        print 'completed in %s', (end_time - start_time) 
  
      if __name__ == '__main__':
         main()
  </code></pre>