用psutil包
创新互联建站-专业网站定制、快速模板网站建设、高性价比霍尔果斯网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式霍尔果斯网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖霍尔果斯地区。费用合理售后完善,10年实体公司更值得信赖。
cpu:
import psutil
psutil.cpu_times()
scputimes(user=3961.46, nice=169.729, system=2150.659, idle=16900.540, iowait=629.59, irq=0.0, softirq=19.42, steal=0.0, guest=0, nice=0.0)
for x in range(3):
... psutil.cpu_percent(interval=1)
...
4.0
5.9
3.8
for x in range(3):
... psutil.cpu_percent(interval=1, percpu=True)
...
[4.0, 6.9, 3.7, 9.2]
[7.0, 8.5, 2.4, 2.1]
[1.2, 9.0, 9.9, 7.2]
for x in range(3):
... psutil.cpu_times_percent(interval=1, percpu=False)
...
scputimes(user=1.5, nice=0.0, system=0.5, idle=96.5, iowait=1.5, irq=0.0, softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0)
scputimes(user=1.0, nice=0.0, system=0.0, idle=99.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0)
scputimes(user=2.0, nice=0.0, system=0.0, idle=98.0, iowait=0.0, irq=0.0, softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0)
psutil.cpu_count()
4
psutil.cpu_count(logical=False)
2
内存:
psutil.virtual_memory()
svmem(total=8374149120L, available=2081050624L, percent=75.1, used=8074080256L, free=300068864L, active=3294920704, inactive=1361616896, buffers=529895424L, cached=1251086336)
psutil.swap_memory()
sswap(total=2097147904L, used=296128512L, free=1801019392L, percent=14.1, sin=304193536, sout=677842944)
在python中可以用id()函数获取对象的内存地址。
#例如:
object = 1 + 2
print(id(object)) #4304947776
python获取微信用户信息、视频、文件路径
Python源码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
def wx_path():
## 获取当前用户名
users = os.path.expandvars('$HOMEPATH')
## 找到3ebffe94.ini配置文件
f = open(r'C:' + users + '\\AppData\\Roaming\\Tencent\\WeChat\\All Users\\config\\3ebffe94.ini')
##读取文件将路径放到wx_location变量里
if f == 'MyDocument:':
wx_location = 'C:' + users + '\Documents\WeChat Files'
else:
wx_location = f.read() + "\WeChat Files"
## 输出路径信息
print(f"\n微信用户信息路径: \"{wx_location}\"\n")
# 程序入口