Trying to display psutil values thus:-
for VM psutil.virtual_memory():
print (VM)
This prints the values but not the names. Any suggestions?
Trying to display psutil values thus:-
for VM psutil.virtual_memory():
print (VM)
This prints the values but not the names. Any suggestions?
Just print it without iterating over it, for debugging and development purposes. This looks like:
svmem(total=16521965568, available=12267257856, percent=25.8, used=3729342464, free=3388936192, active=5169664000, inactive=3971186688, buffers=954048512, cached=8449638400, shared=181248000, slab=3778879488)
It's a named tuple, not a dict, so you're not really supposed to iterate over the "keys". However, there's a slightly naughty ._fields you could use if you really have your heart set on getting a tuple of attribute names.
import psutil
for k, v in psutil.virtual_memory()._asdict().items():
print(k, v)
...prints:
total 16706494464
available 7661907968
percent 54.1
used 7520182272
free 2695786496
active 9574060032
inactive 3523575808
buffers 896020480
cached 5594505216
shared 1172226048
slab 464887808