Python 如何删除键并仅打印命名元组中的数据?
我将命名为tuple作为输出,但我只想使用字段,不想使用键。几天前,我做了一些尝试和错误,但丢失了那段代码Python 如何删除键并仅打印命名元组中的数据?,python,python-3.x,psutil,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.
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\u 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\u nice=0.0)
我如何在不单独打印每个值的情况下实现这一点
详情:
python3.7
Ubuntu 16
我不知道你为什么需要这个,但请你理解
使用str.replace
>>> str(psutil.cpu_times(percpu=flag)).replace('scputimes(', '').replace(')','')
我不知道你为什么需要这个,但是我需要你的理解 使用
str.replace
>>> str(psutil.cpu_times(percpu=flag)).replace('scputimes(', '').replace(')','')
但你为什么需要这个呢?我看不出你的想法有什么不同outputs@JulianSilvestri名称
scputimes
不存在,这是他们想要实现的使用print(tuple(cpuTimes))
@Puneet实际上我必须在文本文件中以json格式存储很多变量,很多对象都有相同的键scputimes,所以我想删除它并只存储值。但是为什么你需要它呢?我看不出你的outputs@JulianSilvestri名称scputimes
不存在,这就是他们想要实现的使用print(tuple(cpuTimes))
@Puneet实际上我必须在文本文件中以json格式存储很多变量,其中许多对象都有相同的键scputimes,所以我想删除它并只存储值。