This article mainly introduces how to obtain the hardware information of various operating systems by using python. The example shows how to obtain the CPU information of Python on windows, Linux, Mac, and other operating systems, for more information about how to obtain the hardware information of various operating systems, see the example in this article. Share it with you for your reference. The details are as follows:
1. windows
Use WMI:
(WMI official website address: http://pypi.python.org/pypi/WMI or click here to download .)
Import wmi w = wmi. WMI () cpus = w. Win32_Processor () for u in cpus: print 'CPU id: ', u. ProcessorId
The running result is as follows:
Cpu id: BFEBFBFF0001067Acpu id: BFEBFBFF0001067A
2. linux
Direct read:
/Proc
The information under the file is all text files. For example, read cpu information:
/Proc/cpuinfo
3. Mac
Use subprocess. Popen ()
Run the following command:
/Usr/sbin/system_profiler SPHardwareDataType
Then the output analysis result is obtained.
I hope this article will help you with Python programming.