How to extract only percentage of psutil.phymem_usage () python

I want to get the percentage of memory usage from psutil.phymem_usage() in python, but when I run the function, it returns this:

 usage(total=520048640L, used=503255040L, free=16793600L, percent=81.5) 

How can I filter it so that only a percentage passes?

0
source share
1 answer

What you get is a named tuple (see also this question ), and you can just access it like any tuple or as an attribute. Assuming you store the return value in the usage variable, you can access the percentage using usage[3] (regular tuple) or usage.percent , with the second option being (imho) the best option. You can also use psutil.phymem_usage().percent .

+2
source

Source: https://habr.com/ru/post/969902/


All Articles