python string split mystery IndexError

Okay ... this is a mystery to me the below code prints:

['03:20:01', 'PM', '262144', '16176136', '98.41', '547744', '11459404', '2096128',   '312', '0.01', '0']
['12:30:01', 'PM', '261748', '16176532', '98.41', '547600', '11459084', '2096128', '312', '0.01', '0']
['10:50:11', 'PM', '257516', '16180764', '98.43', '548064', '11460312', '2096128', '312', '0.01', '0']

but when I try to print c[2] it gives me:

IndexError: list index out of range

What am I missing ?

The code seems straightforward

cmd = 'sar -r -f /xactly/apps/sar/sjcxtlycomp22s/sa05 |sort -g -k4' 
high = subprocess.Popen([cmd],
      stdin=subprocess.PIPE,
      stdout=subprocess.PIPE,
      stderr=subprocess.PIPE,
        shell=True)

memuse = False
count = 0 

sep = re.compile('[\s]+')
for line in high.stdout:
    if line:
        line = line.strip()
        count += 1
        c = sep.split(line)
        print c

Answers


I needed to skip the first three lines of data so I modified it with:

sep = re.compile('[\s]+')
   for line in high.stdout:
       if line:
           line = line.strip()
           count += 1
           if count > 3:
               c = sep.split(line)
               print c[4]

Need Your Help

How to get NWMLS array values' full description using XML query in PHP?

php wsdl full-text-search xmlnode rets

Assume that the below array I got from the NWMLS real estate services,

Castle-ActiveRecord Tutorial with .NET 3.5 broken?

orm .net-3.5 documentation castle-activerecord

Has anyone tried the ActiveRecord Intro Sample with C# 3.5?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.