Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用psutil从python中的scputimes元组中提取特定值_Python_Tuples_Extract - Fatal编程技术网

使用psutil从python中的scputimes元组中提取特定值

使用psutil从python中的scputimes元组中提取特定值,python,tuples,extract,Python,Tuples,Extract,我已经兜了几个小时的圈子,试图找出如何从元组中提取数据。我找到了一种从psutil.getloadavg获取数据的方法,但使用同样的方法对psutil.cpu\u times\u%不起作用 所以,假设我运行这个命令 print(psutil.cpu_times_percent(interval=2)) 我得到了以下回复 scputimes(user=6.5, nice=0.0, system=4.5, idle=89.0, iowait=0.0, irq=0.0, softirq=0.0, s

我已经兜了几个小时的圈子,试图找出如何从元组中提取数据。我找到了一种从psutil.getloadavg获取数据的方法,但使用同样的方法对psutil.cpu\u times\u%不起作用

所以,假设我运行这个命令

print(psutil.cpu_times_percent(interval=2))
我得到了以下回复

scputimes(user=6.5, nice=0.0, system=4.5, idle=89.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0)
现在我只想提取空闲数,但如何提取。 我试过类似的方法,但都没用

scpu = psutil.cpu_times_percent(interval=2)
for i, in scpu:
    print(i)


以百分比表示的空闲时间仅为:

psutil.cpu_times_percent(interval=2).idle

太简单了,谢谢。
psutil.cpu_times_percent(interval=2).idle