0

I want to get the memory used percentage 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 the percent comes through?

Hasturkun
  • 35,395
  • 6
  • 71
  • 104
ryan27968
  • 437
  • 3
  • 7
  • 14

1 Answers1

2

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 a variable usage, you can access the percentage using usage[3](regular tuple access) or usage.percent, with the second option being (imho) the most best option. You can also use psutil.phymem_usage().percent.

Community
  • 1
  • 1
Daan Wilmer
  • 937
  • 4
  • 13