使用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:\\', fsty