您好,欢迎来到九壹网。
搜索
您的当前位置:首页使用python获取电脑的磁盘信息

使用python获取电脑的磁盘信息

来源:九壹网

源链接:

使用Python获取电脑的磁盘信息需要借助于第三方的模块psutil,这个模块需要自己安装,纯粹的CPython下面不具备这个功能。

在PyCharm交互界面中进行如下演示:

查看电脑的磁盘分区:

输出:

  1. C:\Users\ASUS\venv\untitled\Scripts\python.exe E:/pythonProject/untitled/Public_Other/test_Public_Other/显示系统IO.py

  2. C盘信息: sdiskpart(device='C:\\', mountpoint='C:\\', fstype='NTFS', opts='rw,fixed')

  3. D盘信息: sdiskpart(device='D:\\', mountpoint='D:\\', fstype='NTFS', opts='rw,fixed')

  4. E盘信息: sdiskpart(device='E:\\', mountpoint='E:\\', fstype='NTFS', opts='rw,fixed')

  5. 获取磁盘字段: C:\ D:\ E:\

  6. 数据类型: <class 'list'>

查看电脑的磁盘使用百分比:

  1. p = psutil.disk_usage(d[0][0]) #C盘

  2. print('C盘使用百分比:',p)

  3. p = psutil.disk_usage(d[1][0]) #D盘

  4. print('D盘使用百分比:',p)

  5. p = psutil.disk_usage(d[2][0]) #E盘

  6. print('E盘使用百分比:',p)

  7. print('数据类型',type(p))

  8. p_all = psutil.disk_usage('/')

输出:

  1. C盘使用百分比: sdiskusage(total=125139517440, used=71230517248, free=53909000192, percent=56.9)

  2. D盘使用百分比: sdiskusage(total=600122060800, used=471762903040, free=128359157760, percent=78.6)

  3. E盘使用百分比: sdiskusage(total=399268376576, used=2077602048, free=191507734528, percent=52.0)

  4. 数据类型 <class 'psutil._common.sdiskusage'>

查看电脑磁盘的IO计数:

 1.io = psutil.disk_io_counters()

 2.print('磁盘IO:',io)

 3.print('数据类型:',type(io),'\n')

输出:

 1.磁盘IO: sdiskio(read_count=188773, write_count=99822, read_bytes=4444965888, write_bytes=2584822784,        read_time=3073, write_time=297)

 2.数据类型: <class 'psutil._common.sdiskio'>

查看电脑磁盘分区(物理分区)的IO计数:

  1. f = psutil.disk_io_counters(perdisk=True)

  2. print('分区信息(物理分区):',f)

  3. print('数据类型:',type(f))

  4. print('第一分区:',f['PhysicalDrive0'])

  5. print('第二分区:',f['PhysicalDrive1'])

输出:

  1. 分区信息(物理分区): {'PhysicalDrive0': sdiskio(read_count=462, write_count=3934, read_bytes=1487477248, write_bytes=744856, read_time=2772, write_time=31), 'PhysicalDrive1': sdiskio(read_count=141881, write_count=95888, read_bytes=29574880, write_bytes=2510332928, read_time=301, write_time=266)}

  2. 数据类型: <class 'dict'>

  3. 第一分区: sdiskio(read_count=462, write_count=3934, read_bytes=1487477248, write_bytes=744856, read_time=2772, write_time=31)

  4. 第二分区: sdiskio(read_count=141881, write_count=95888, read_bytes=29574880, write_bytes=2510332928, read_time=301, write_time=266)

  5. [sdiskpart(device='C:\\', mountpoint='C:\\', fstype='NTFS', opts='rw,fixed'), sdiskpart(device='D:\\', mountpoint='D:\\', fstype='NTFS', opts='rw,fixed'), sdiskpart(device='E:\\', mountpoint='E:\\', fstype='NTFS', opts='rw,fixed')]

  6. sdiskusage(total=125139517440, used=71230517248, free=53909000192, percent=56.9)

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 91gzw.com 版权所有 湘ICP备2023023988号-2

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务