您的位置:首页 > 编程语言 > Python开发

python开发_platform_获取操作系统详细信息工具

2016-07-22 17:44 766 查看


python开发_platform_获取操作系统详细信息工具

'''
python中,platform模块给我们提供了很多方法去获取操作系统的信息
如:
import platform
platform.platform()   #获取操作系统名称及版本号,'Windows-7-6.1.7601-SP1'
platform.version()    #获取操作系统版本号,'6.1.7601'
platform.architecture()   #获取操作系统的位数,('32bit', 'WindowsPE')
platform.machine()    #计算机类型,'x86'
platform.node()       #计算机的网络名称,'hongjie-PC'
platform.processor()  #计算机处理器信息,'x86 Family 16 Model 6 Stepping 3, AuthenticAMD'
platform.uname()      #包含上面所有的信息汇总,uname_result(system='Windows', node='hongjie-PC',
release='7', version='6.1.7601', machine='x86', processor='x86 Family
16 Model 6 Stepping 3, AuthenticAMD')

还可以获得计算机中python的一些信息:
import platform
platform.python_build()
platform.python_compiler()
platform.python_branch()
platform.python_implementation()
platform.python_revision()
platform.python_version()
platform.python_version_tuple()
'''


下面是我做的demo:

运行效果:

=======================================================

代码部分:

=======================================================

1 #python platform  2
3 #Author   :   Hongten  4 #Mailto   :   hongtenzone@foxmail.com  5 #Blog     :   http://www.cnblogs.com/hongten  6 #QQ       :   648719819  7 #Version  :   1.0  8 #Create   :   2013-08-28  9
10 import platform
11
12 ''' 13     python中,platform模块给我们提供了很多方法去获取操作系统的信息
14     如:
15         import platform
16         platform.platform()   #获取操作系统名称及版本号,'Windows-7-6.1.7601-SP1'
17         platform.version()    #获取操作系统版本号,'6.1.7601'
18         platform.architecture()   #获取操作系统的位数,('32bit', 'WindowsPE')
19         platform.machine()    #计算机类型,'x86'
20         platform.node()       #计算机的网络名称,'hongjie-PC'
21         platform.processor()  #计算机处理器信息,'x86 Family 16 Model 6 Stepping 3, AuthenticAMD'
22         platform.uname()      #包含上面所有的信息汇总,uname_result(system='Windows', node='hongjie-PC',
23                                release='7', version='6.1.7601', machine='x86', processor='x86 Family
24                                16 Model 6 Stepping 3, AuthenticAMD')
25
26         还可以获得计算机中python的一些信息:
27         import platform
28         platform.python_build()
29         platform.python_compiler()
30         platform.python_branch()
31         platform.python_implementation()
32         platform.python_revision()
33         platform.python_version()
34         platform.python_version_tuple()
35 ''' 36
37 #global var 38 #是否显示日志信息 39 SHOW_LOG = True
40
41 def get_platform():
42     '''获取操作系统名称及版本号''' 43     return platform.platform()
44
45 def get_version():
46     '''获取操作系统版本号''' 47     return platform.version()
48
49 def get_architecture():
50     '''获取操作系统的位数''' 51     return platform.architecture()
52
53 def get_machine():
54     '''计算机类型''' 55     return platform.machine()
56
57 def get_node():
58     '''计算机的网络名称''' 59     return platform.node()
60
61 def get_processor():
62     '''计算机处理器信息''' 63     return platform.processor()
64
65 def get_system():
66     '''获取操作系统类型''' 67     return platform.system()
68
69 def get_uname():
70     '''汇总信息''' 71     return platform.uname()
72
73 def get_python_build():
74     ''' the Python build number and date as strings''' 75     return platform.python_build()
76
77 def get_python_compiler():
78     '''Returns a string identifying the compiler used for compiling Python''' 79     return platform.python_compiler()
80
81 def get_python_branch():
82     '''Returns a string identifying the Python implementation SCM branch''' 83     return platform.python_branch()
84
85 def get_python_implementation():
86     '''Returns a string identifying the Python implementation. Possible return values are: ‘CPython’, ‘IronPython’, ‘Jython’, ‘PyPy’.''' 87     return platform.python_implementation()
88
89 def get_python_version():
90     '''Returns the Python version as string 'major.minor.patchlevel'
91     ''' 92     return platform.python_version()
93
94 def get_python_revision():
95     '''Returns a string identifying the Python implementation SCM revision.''' 96     return platform.python_revision()
97
98 def get_python_version_tuple():
99     '''Returns the Python version as tuple (major, minor, patchlevel) of strings'''100     return platform.python_version_tuple()
101
102 def show_python_all_info():
103     '''打印python的全部信息'''104     print('The Python build number and date as strings : [{}]'.format(get_python_build()))
105     print('Returns a string identifying the compiler used for compiling Python : [{}]'.format(get_python_compiler()))
106     print('Returns a string identifying the Python implementation SCM branch : [{}]'.format(get_python_branch()))
107     print('Returns a string identifying the Python implementation : [{}]'.format(get_python_implementation()))
108     print('The version of Python : [{}]'.format(get_python_version()))
109     print('Python implementation SCM revision : [{}]'.format(get_python_revision()))
110     print('Python version as tuple : [{}]'.format(get_python_version_tuple()))
111
112 def show_python_info():
113     '''只打印python的信息,没有解释部分'''114     print(get_python_build())
115     print(get_python_compiler())
116     print(get_python_branch())
117     print(get_python_implementation())
118     print(get_python_version())
119     print(get_python_revision())
120     print(get_python_version_tuple())
121
122 def show_os_all_info():
123     '''打印os的全部信息'''124     print('获取操作系统名称及版本号 : [{}]'.format(get_platform()))
125     print('获取操作系统版本号 : [{}]'.format(get_version()))
126     print('获取操作系统的位数 : [{}]'.format(get_architecture()))
127     print('计算机类型 : [{}]'.format(get_machine()))
128     print('计算机的网络名称 : [{}]'.format(get_node()))
129     print('计算机处理器信息 : [{}]'.format(get_processor()))
130     print('获取操作系统类型 : [{}]'.format(get_system()))
131     print('汇总信息 : [{}]'.format(get_uname()))
132
133 def show_os_info():
134     '''只打印os的信息,没有解释部分'''135     print(get_platform())
136     print(get_version())
137     print(get_architecture())
138     print(get_machine())
139     print(get_node())
140     print(get_processor())
141     print(get_system())
142     print(get_uname())
143
144 def test():
145     print('操作系统信息:')
146     if SHOW_LOG:
147         show_os_all_info()
148     else:
149         show_os_info()
150     print('#' * 50)
151     print('计算机中的python信息:')
152     if SHOW_LOG:
153         show_python_all_info()
154     else:
155         show_python_info()
156
157 def init():
158     global SHOW_LOG
159     SHOW_LOG = True
160
161 def main():
162     init()
163     test()
164
165 if __name__ == '__main__':
166     main()


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: