0

对不起,如果这有点含糊,或者已经被问到,但我不确定术语,所以我无法谷歌它。我正在寻找的是如何分配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

4

1 回答 1

1

它返回一个命名元组(称为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:
于 2013-05-19T17:52:22.960 回答