Python: how to obtain hardware information of each operating system.
This example describes how to obtain the hardware information of each operating system using python. 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.