设为首页 收藏本站
查看: 1282|回复: 0

[经验分享] python开发_platform_获取操作系统详细信息工具

[复制链接]

尚未签到

发表于 2015-4-22 11:30:03 | 显示全部楼层 |阅读模式
'''
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:
  运行效果:
DSC0000.png
  =======================================================
  代码部分:
  =======================================================



  1 #python platform
  2
  3 #Author   :   Hongten
  4 #Mailto   :   hongtenzone@foxmail.com
  5 #Blog     :   http://www.iyunv.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()
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-59584-1-1.html 上篇帖子: Emacs-for-python 增强计划 下篇帖子: Python实例讲解——wxPython的基本控件实现
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表