Getting total/free RAM from within Python

后端 未结 5 1691
被撕碎了的回忆
被撕碎了的回忆 2021-02-08 15:59

From within a Python application, how can I get the total amount of RAM of the system and how much of it is currently free, in a cross-platform way?

Ideally, the amount

5条回答
  •  伪装坚强ぢ
    2021-02-08 16:31

    In windows I use this method. It's kinda hacky but it works using standard os library:

    import os
    process = os.popen('wmic memorychip get capacity')
    result = process.read()
    process.close()
    totalMem = 0
    for m in result.split("  \r\n")[1:-1]:
        totalMem += int(m)
    print totalMem / (1024**3)
    

提交回复
热议问题