python字符串拆分神秘索引

2024-09-30 06:12:47 发布

您现在位置:Python中文网/ 问答频道 /正文

好吧。。。这对我来说是个谜 以下代码打印:

['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']

但当我试图打印c[2]时,它会给我:

^{pr2}$

我错过了什么?在

代码看起来很简单

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

Tags: apps代码cmdcountstdoutlinesepsubprocess
1条回答
网友
1楼 · 发布于 2024-09-30 06:12:47

我需要跳过前三行数据,因此我修改了它:

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]

相关问题 更多 >

    热门问题