如何删除键并仅打印命名元组中的数据?
How to remove key and print only data in named 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
我不知道你为什么需要这个,但为了理解而回答
使用 str.replace
.
>>> str(psutil.cpu_times(percpu=flag)).replace('scputimes(', '').replace(')','')
我得到命名元组作为输出,但我只想使用字段而不是键,几天前我通过一些试验和错误进行了试验,但丢失了那段代码。
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
我不知道你为什么需要这个,但为了理解而回答
使用 str.replace
.
>>> str(psutil.cpu_times(percpu=flag)).replace('scputimes(', '').replace(')','')