使用Python获取电脑的磁盘信息需要借助于第三方的模块psutil,这个模块需要自己安装,纯粹的CPython下面不具备这个功能。
在PyCharm交互界面中进行如下演示:
查看电脑的磁盘分区:
d = psutil.disk_partitions()
print('C盘信息:',d[0])
print('D盘信息:',d[1])
print('E盘信息:',d[2])
print('获取磁盘字段:',d[0][0],d[1][0],d[2][0])
print('数据类型:',type(d),'\n')
输出:
C:\Users\ASUS\venv\untitled\Scripts\python.exe E:/pythonProject/untitled/Public_Other/test_Public_Other/显示系统IO.py
C盘信息: sdiskpart(device='C:\\', mountpoint='C:\\', fstype='NTFS', opts='rw,fixed')
D盘信息: sdiskpart(device='D:\\', mountpoint='D:\\', fstype='NTFS', opts='rw,fixed')
E盘信息: sdiskpart(device='E:\\', mountpoint='E:\\', fstype='NTFS', opts='rw,fixed')
获取磁盘字段: C:\ D:\ E:\
数据类型: <class 'list'>
------------------------------------------------------------------------------------------------------------------

本文通过Python的psutil模块详细介绍了如何获取电脑的磁盘分区、磁盘使用百分比以及磁盘IO计数等信息,包括物理分区的IO计数。
&spm=1001.2101.3001.5002&articleId=82799952&d=1&t=3&u=44f81c80309b4df39a5afd4e698caa40)
282

被折叠的 条评论
为什么被折叠?



