python利用platform模块获取系统信息
Pythonplatform模块
platform模块用于查看当前操作系统的信息,来采集系统版本位数计算机类型名称内核等一系列信息。
使用方法:
#coding:utf-8
importplatform
t=platform.system()
print(t)
#coding=utf-8
#platform_mode.py
importplatform
'''
python中,platform模块给我们提供了很多方法去获取操作系统的信息
如:
importplatform
platform.platform()#获取操作系统名称及版本号,'Linux-3.13.0-46-generic-i686-with-Deepin-2014.2-trusty'
platform.version()#获取操作系统版本号,'#76-UbuntuSMPThuFeb2618:52:49UTC2015'
platform.architecture()#获取操作系统的位数,('32bit','ELF')
platform.machine()#计算机类型,'i686'
platform.node()#计算机的网络名称,'XF654'
platform.processor()#计算机处理器信息,''i686'
platform.uname()#包含上面所有的信息汇总,('Linux','XF654','3.13.0-46-generic','#76-UbuntuSMPThuFeb2618:52:49UTC2015','i686','i686')
还可以获得计算机中python的一些信息:
importplatform
platform.python_build()
platform.python_compiler()
platform.python_branch()
platform.python_implementation()
platform.python_revision()
platform.python_version()
platform.python_version_tuple()
'''
#globalvar
#是否显示日志信息
SHOW_LOG=True
defget_platform():
'''获取操作系统名称及版本号'''
returnplatform.platform()
defget_version():
'''获取操作系统版本号'''
returnplatform.version()
defget_architecture():
'''获取操作系统的位数'''
returnplatform.architecture()
defget_machine():
'''计算机类型'''
returnplatform.machine()
defget_node():
'''计算机的网络名称'''
returnplatform.node()
defget_processor():
'''计算机处理器信息'''
returnplatform.processor()
defget_system():
'''获取操作系统类型'''
returnplatform.system()
defget_uname():
'''汇总信息'''
returnplatform.uname()
defget_python_build():
'''thePythonbuildnumberanddateasstrings'''
returnplatform.python_build()
defget_python_compiler():
'''ReturnsastringidentifyingthecompilerusedforcompilingPython'''
returnplatform.python_compiler()
defget_python_branch():
'''ReturnsastringidentifyingthePythonimplementationSCMbranch'''
returnplatform.python_branch()
defget_python_implementation():
'''ReturnsastringidentifyingthePythonimplementation.Possiblereturnvaluesare:‘CPython',‘IronPython',‘Jython',‘PyPy'.'''
returnplatform.python_implementation()
defget_python_version():
'''ReturnsthePythonversionasstring'major.minor.patchlevel'
'''
returnplatform.python_version()
defget_python_revision():
'''ReturnsastringidentifyingthePythonimplementationSCMrevision.'''
returnplatform.python_revision()
defget_python_version_tuple():
'''ReturnsthePythonversionastuple(major,minor,patchlevel)ofstrings'''
returnplatform.python_version_tuple()
defshow_os_all_info():
'''打印os的全部信息'''
print('获取操作系统名称及版本号:[{}]'.format(get_platform()))
print('获取操作系统版本号:[{}]'.format(get_version()))
print('获取操作系统的位数:[{}]'.format(get_architecture()))
print('计算机类型:[{}]'.format(get_machine()))
print('计算机的网络名称:[{}]'.format(get_node()))
print('计算机处理器信息:[{}]'.format(get_processor()))
print('获取操作系统类型:[{}]'.format(get_system()))
print('汇总信息:[{}]'.format(get_uname()))
defshow_os_info():
'''只打印os的信息,没有解释部分'''
print(get_platform())
print(get_version())
print(get_architecture())
print(get_machine())
print(get_node())
print(get_processor())
print(get_system())
print(get_uname())
defshow_python_all_info():
'''打印python的全部信息'''
print('ThePythonbuildnumberanddateasstrings:[{}]'.format(get_python_build()))
print('ReturnsastringidentifyingthecompilerusedforcompilingPython:[{}]'.format(get_python_compiler()))
print('ReturnsastringidentifyingthePythonimplementationSCMbranch:[{}]'.format(get_python_branch()))
print('ReturnsastringidentifyingthePythonimplementation:[{}]'.format(get_python_implementation()))
print('TheversionofPython:[{}]'.format(get_python_version()))
print('PythonimplementationSCMrevision:[{}]'.format(get_python_revision()))
print('Pythonversionastuple:[{}]'.format(get_python_version_tuple()))
defshow_python_info():
'''只打印python的信息,没有解释部分'''
print(get_python_build())
print(get_python_compiler())
print(get_python_branch())
print(get_python_implementation())
print(get_python_version())
print(get_python_revision())
print(get_python_version_tuple())
deftest():
print('操作系统信息:')
ifSHOW_LOG:
show_os_all_info()
else:
show_os_info()
print('#'*50)
print('计算机中的python信息:')
ifSHOW_LOG:
show_python_all_info()
else:
show_python_info()
definit():
globalSHOW_LOG
SHOW_LOG=True
defmain():
init()
test()
if__name__=='__main__':
main()
Windows
操作系统信息:
获取操作系统名称及版本号:[Windows-7-6.1.7601-SP1]
获取操作系统版本号:[6.1.7601]
获取操作系统的位数:[('32bit','WindowsPE')]
计算机类型:[AMD64]
计算机的网络名称:[dw2019]
计算机处理器信息:[Intel64Family6Model69Stepping1,GenuineIntel]
获取操作系统类型:[Windows]
汇总信息:[uname_result(system='Windows',node='dw2019',release='7',version='6.1.7601',machine='AMD64',processor='Intel64Family6Model69Stepping1,GenuineIntel')]
##################################################
计算机中的python信息:
ThePythonbuildnumberanddateasstrings:[('v3.3.3:c3896275c0f6','Nov18201321:18:40')]
ReturnsastringidentifyingthecompilerusedforcompilingPython:[MSCv.160032bit(Intel)]
ReturnsastringidentifyingthePythonimplementationSCMbranch:[v3.3.3]
ReturnsastringidentifyingthePythonimplementation:[CPython]
TheversionofPython:[3.3.3]
PythonimplementationSCMrevision:[c3896275c0f6]
Pythonversionastuple:[('3','3','3')]
以上就是python利用platform模块获取系统信息的详细内容,更多关于Pythonplatform模块的资料请关注毛票票其它相关文章!