Search code examples
pythonnamedtuplepsutil

How to print contents of named tuple from PSUTIL


Trying to display psutil values thus:-

  for VM psutil.virtual_memory():
      print (VM)

This prints the values but not the names. Any suggestions?


Solution

  • 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