Search code examples
pythonpython-3.xwindowspsutil

How to get RAM Usage percentage in Python?


Now I know there's psutil module for the use:

import psutil
a=psutil.virtual_memory()
print(a)

And it shows this output:

svmem(total=4238442496, available=1836089344, percent=56.7, used=2402353152, free=1836089344)

It has got percentage, but I only want percentage of RAM usage without all other features like used, free, etc. Is it possible ? Please sort this out. Thanks in advance for answers.


Solution

  • Just a minor change:

    import psutil
    
    a = psutil.virtual_memory()
    print(a.percent) # Here's a change
    

    Hope this helps :)