Home > Backend Development > Python Tutorial > python获取各操作系统硬件信息的方法

python获取各操作系统硬件信息的方法

WBOY
Release: 2016-06-06 11:18:12
Original
1958 people have browsed it

本文实例讲述了python获取各操作系统硬件信息的方法。分享给大家供大家参考。具体如下:

1. windows

使用WMI:

(WMI官网地址:http://pypi.python.org/pypi/WMI 或 点击此处本站下载。)

import wmi 
w=wmi.WMI() 
cpus=w.Win32_Processor() 
for u in cpus: 
  print 'cpu id:',u.ProcessorId
Copy after login

运行结果如下:

cpu id: BFEBFBFF0001067A
cpu id: BFEBFBFF0001067A
Copy after login

2. linux

直接读取:

/proc
文件下面的信息,都是些文本文件。如读取cpu信息:
/proc/cpuinfo

3. Mac

使用subprocess.Popen()

执行相应的命令:
/usr/sbin/system_profiler SPHardwareDataType
然后再得到输出分析结果

希望本文所述对大家的Python程序设计有所帮助。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template