各位大大,小弟是python新手,目前遇到一个问题,请各位大大帮帮忙
程式的主要目的是把ipmitool sensor list的结果写入sensorlist.txt
之后再取出第一列(row[0])的值,把结果print出来,code如下:
import subprocess
sensorlist = open( "sensorlist.txt", "w")
p = subprocess.Popen("ipmitool sensor list", stdout=subprocess.PIPE,
shell=True)
(output, err) = p.communicate()
sensorlist.write(output)
f = open( "sensorlist.txt", "r")
files = f.readlines()
sensor_list = [i.split("|") for i in files]
sensor_name = [row[0] for row in sensor_list ]
noSpaceSensorName = [x.strip(' ') for x in sensor_name]
print(noSpaceSensorName)
出来的结果是一个list,也没出现什么error,问题是为什么不是所有row[0]的值呢?
只出现一半的row[0]的值在营幕上,请各位大大帮忙,3Q