很抱歉,如果这有点模糊,或者已经被问过,但我不确定术语,所以我不能谷歌。我正在寻找的是如何将psutil.virtual_memory()
赋予不同变量的参数分配
例如,调用psutil.virtual_memory()
会提供(total=8374149120L, available=1247768576L, percent=85.1, used=8246628352L, free=127520768L, active=3208777728, inactive=1133408256, buffers=342413312L, cached=777834496)
我只想获取percent
值,并将其分配给变量。我怎么能这样呢?
文档:https://code.google.com/p/psutil/wiki/Documentation#Memory
答案 0 :(得分:1)
返回namedtuple(称为vrem
),因此请使用percent = psutil.virtual_memory().percent
>>> help(psutil.virtual_memory)
Help on function virtual_memory in module psutil:
virtual_memory()
Return statistics about system memory usage as a namedtuple
including the following fields, expressed in bytes: