简体   繁体   English

如何获取 Python 中的 RAM 使用百分比?

[英]How to get RAM Usage percentage in Python?

Now I know there's psutil module for the use:现在我知道有psutil模块可供使用:

import psutil
a=psutil.virtual_memory()
print(a)

And it shows this output:它显示了这个 output:

svmem(total=4238442496, available=1836089344, percent=56.7, used=2402353152, free=1836089344) svmem(总计=4238442496,可用=1836089344,百分比=56.7,使用=2402353152,空闲=1836089344)

It has got percentage, but I only want percentage of RAM usage without all other features like used, free, etc. Is it possible?它有百分比,但我只想要 RAM 使用百分比,而不需要所有其他功能,如已使用、免费等。这可能吗? Please sort this out.请整理一下。 Thanks in advance for answers.提前感谢您的回答。

Just a minor change:只是一个小改动:

import psutil

a = psutil.virtual_memory()
print(a.percent) # Here's a change

Hope this helps:)希望这可以帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM