如何删除键并仅打印命名元组中的数据?

时间:2019-02-12 14:30:40

标签: python python-3.x psutil

我将命名为tuple作为输出,但我只想使用字段而不是键,我经过几天的尝试和错误却做了几天,但丢失了这段代码。

import psutil

cpuTimes = psutil.cpu_times(percpu=flag)
print(cpuTimes)

输出:

scputimes(user=49296.07, nice=223.37, system=7839.13, idle=217461.5, iowait=209.82, irq=0.0, softirq=91.75, steal=0.0, guest=0.0, guest_nice=0.0)

在上面的输出中,我得到scputimes,但是我需要删除该预期的输出:

(user=49296.07, nice=223.37, system=7839.13, idle=217461.5, iowait=209.82, irq=0.0, softirq=91.75, steal=0.0, guest=0.0, guest_nice=0.0)

在不单独打印每个值的情况下怎么办?

详细信息:

Python 3.7
Ubuntu 16

1 个答案:

答案 0 :(得分:3)

我不知道你为什么需要这个,但回答以了解 使用str.replace

>>> str(psutil.cpu_times(percpu=flag)).replace('scputimes(', '').replace(')','')