Reputation: 109
I'm making a function in python that returns memory usage percentage, and I'm using psutil.
When I tried to run print(psutil.virtual_memory().percent()) I got an error that int object is not callable.
Currently, I'm doing this:
mem = psutil.virtual_memory()
mem = mem.percent()
print("RAM: " + str(mem) + "%")
I'm expecting it to return a percentage instead of an error.
Upvotes: 0
Views: 1012
Reputation: 41116
According to [ReadTheDocs.psutil]: psutil.virtual_memory() (emphasis is mine):
Return statistics about system memory usage as a named tuple including the following fields, expressed in bytes.
So, you must not call mem.percent()
.
Example:
>>> import psutil >>> >>> mem = psutil.virtual_memory() >>> mem svmem(total=34190491648, available=14239588352, percent=58.4, used=19950903296, free=14239588352) >>> >>> mem.percent 58.4
Upvotes: 1