pythonplatform标识_Python中 Platform模块

1 importplatform2

3 '''

4 python中,platform模块给我们提供了很多方法去获取操作系统的信息5 如:6 import platform7 platform.platform() #获取操作系统名称及版本号,'Windows-7-6.1.7601-SP1'8 platform.version() #获取操作系统版本号,'6.1.7601'9 platform.architecture() #获取操作系统的位数,('32bit', 'WindowsPE')10 platform.machine() #计算机类型,'x86'11 platform.node() #计算机的网络名称,'Natural-PC'12 platform.processor() #计算机处理器信息,'x86 Family 16 Model 6 Stepping 3, AuthenticAMD'13 platform.uname() #包含上面所有的信息汇总,uname_result(system='Windows', node='hongjie-PC',14 release='7', version='6.1.7601', machine='x86', processor='x86 Family15 16 Model 6 Stepping 3, AuthenticAMD')16 还可以获得计算机中python的一些信息:17 import platform18 platform.python_build()19 platform.python_compiler()20 platform.python_branch()21 platform.python_implementation()22 platform.python_revision()23 platform.python_version()24 platform.python_version_tuple()25 '''

26

27 #global var

28 #是否显示日志信息

29 SHOW_LOG =True30

31 defget_platform():32 '''获取操作系统名称及版本号'''

33 returnplatform.platform()34

35 defget_version():36 '''获取操作系统版本号'''

37 returnplatform.version()38

39 defget_architecture():40 '''获取操作系统的位数'''

41 returnplatform.architecture()42

43 defget_machine():44 '''计算机类型'''

45 returnplatform.machine()46

47 defget_node():48 '''计算机的网络名称'''

49 returnplatform.node()50

51 defget_processor():52 '''计算机处理器信息'''

53 returnplatform.processor()54

55 defget_system():56 '''获取操作系统类型'''

57 returnplatform.system()58

59 defget_uname():60 '''汇总信息'''

61 returnplatform.uname()62

63 defget_python_build():64 '''the Python build number and date as strings'''

65 returnplatform.python_build()66

67 defget_python_compiler():68 '''Returns a string identifying the compiler used for compiling Python'''

69 returnplatform.python_compiler()70

71 defget_python_branch():72 '''Returns a string identifying the Python implementation SCM branch'''

73 returnplatform.python_branch()74

75 defget_python_implementation():76 '''Returns a string identifying the Python implementation. Possible return values are: ‘CPython’, ‘IronPython’, ‘Jython’, ‘PyPy’.'''

77 returnplatform.python_implementation()78

79 defget_python_version():80 '''Returns the Python version as string 'major.minor.patchlevel'81 '''

82 returnplatform.python_version()83

84 defget_python_revision():85 '''Returns a string identifying the Python implementation SCM revision.'''

86 returnplatform.python_revision()87

88 defget_python_version_tuple():89 '''Returns the Python version as tuple (major, minor, patchlevel) of strings'''

90 returnplatform.python_version_tuple()91

92 defshow_python_all_info():93 '''打印python的全部信息'''

94 print('The Python build number and date as strings : [{}]'.format(get_python_build()))95 print('Returns a string identifying the compiler used for compiling Python : [{}]'.format(get_python_compiler()))96 print('Returns a string identifying the Python implementation SCM branch : [{}]'.format(get_python_branch()))97 print('Returns a string identifying the Python implementation : [{}]'.format(get_python_implementation()))98 print('The version of Python : [{}]'.format(get_python_version()))99 print('Python implementation SCM revision : [{}]'.format(get_python_revision()))100 print('Python version as tuple : [{}]'.format(get_python_version_tuple()))101

102 defshow_python_info():103 '''只打印python的信息,没有解释部分'''

104 print(get_python_build())105 print(get_python_compiler())106 print(get_python_branch())107 print(get_python_implementation())108 print(get_python_version())109 print(get_python_revision())110 print(get_python_version_tuple())111

112 defshow_os_all_info():113 '''打印os的全部信息'''

114 print('获取操作系统名称及版本号 : [{}]'.format(get_platform()))115 print('获取操作系统版本号 : [{}]'.format(get_version()))116 print('获取操作系统的位数 : [{}]'.format(get_architecture()))117 print('计算机类型 : [{}]'.format(get_machine()))118 print('计算机的网络名称 : [{}]'.format(get_node()))119 print('计算机处理器信息 : [{}]'.format(get_processor()))120 print('获取操作系统类型 : [{}]'.format(get_system()))121 print('汇总信息 : [{}]'.format(get_uname()))122

123 defshow_os_info():124 '''只打印os的信息,没有解释部分'''

125 print(get_platform())126 print(get_version())127 print(get_architecture())128 print(get_machine())129 print(get_node())130 print(get_processor())131 print(get_system())132 print(get_uname())133

134 deftest():135 print('操作系统信息:')136 ifSHOW_LOG:137 show_os_all_info()138 else:139 show_os_info()140 print('#' * 50)141 print('计算机中的python信息:')142 ifSHOW_LOG:143 show_python_all_info()144 else:145 show_python_info()146

147 definit():148 globalSHOW_LOG149 SHOW_LOG =True150

151 defmain():152 init()153 test()154

155 if __name__ == '__main__':156 main()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值