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

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   :   [email protected]
  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()

时间: 2024-07-28 20:22:00

python开发_platform_获取操作系统详细信息工具的相关文章

python开发 getpass获取操作系统登陆名

需用使用python getpass模块 import getpass def get_system_user_name(): return getpass.getuser() def main(): username = get_system_user_name() print ('The system user\'s name is:[{}]'.format(username)) if __name__ == "__main__": main() 打印输出:(可以看到登陆名为adm

TriAquae 是一款由国产的基于Python开发的开源批量部署管理工具

怀着鸡动的心情跟大家介绍一款国产开源运维软件TriAquae,轻松帮你搞定大部分运维工作!TriAquae 是一款由国产的基于Python开发的开源批量部署管理工具,可以允许用户通过一台控制端管理上千台远程Linux服务器,开发者根据多年运维经验以及运维工程师日常工作的需求开发了很多实用的功能,该工具非常实用,并且使用简单,分分钟即可完成安装并开始利用TriAquae管理你的网络,此软件还在不断的开发和更新,目前已实现以下功能: •        支持WEB界面,所有以以下功能均以在WEB界面上

[课程设计]Scrum 3.4 多鱼点餐系统开发进度(下单详细信息页面&会员信息页面)

Scrum 3.4 多鱼点餐系统开发进度(下单详细信息页面&会员信息页面) 1.团队名称:重案组 2.团队目标:长期经营,积累客户充分准备,伺机而行 3.团队口号:矢志不渝,追求完美 4.团队选题:餐厅到店点餐系统WEB 5.Sprint 3时间:12.09-12.18 重案组成员   姓名 学号 博客链接 Github链接 队长 黄冠锋 201406114134 http://www.cnblogs.com/hgf520/ https://github.com/crown999   卢利钦 2

[课程设计]Scrum 3.3 多鱼点餐系统开发进度(下单详细信息页面设计)

Scrum 3.3 多鱼点餐系统开发进度(下单详细信息页面设计)  1.团队名称:重案组 2.团队目标:长期经营,积累客户充分准备,伺机而行 3.团队口号:矢志不渝,追求完美 4.团队选题:餐厅到店点餐系统WEB 5.Sprint 3时间:12.09-12.18 重案组成员   姓名 学号 博客链接 Github链接 队长 黄冠锋 201406114134 http://www.cnblogs.com/hgf520/ https://github.com/crown999   卢利钦 20140

【Android Developers Training】 99. 获取联系人详细信息

注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer.android.com/training/contacts-provider/retrieve-details.html 这节课将会展示如何获取一个联系人的详细数据,比如电子邮件地址,电话号码,等等.当用户获得一个联系人后,他会想要查看他的详细信息.你可以展示给他们所有的信息,或者只展示某一特定类

Unity获取系统详细信息

为了方便以后直接拿来用,所以这次总结一下,有些还没有了解其意. 1 using UnityEngine; 2 using System.Collections; 3 /// <summary> 4 /// 获取当前设备信息 5 /// </summary> 6 public class GetSystemInfo : MonoBehaviour { 7 8 string systemInfo; 9 // Use this for initialization 10 void Sta

Android开发之获取所有软件信息

程序运行效果图: 程序代码: /** * 获取所有软件信息 * 1.通过异步的方式显示系统中所有软件 * 2.单击打开指定软件 * 3.将所有软件的包名和activity名保存的本地SharedPreferences * @author jph * Date:2014.09.21 */ public class ScanPackage1 extends Activity { /**扫描成功**/ private final static int FLAG_LOAD_SUCCESS=0x10001

批处理获取操作系统版本信息

为了使得批处理命令获取更大的通用性,有时需要获取操作系统版本.今天为此搜了一些资料,网上的说法是Ver.注册表.WMI都可以.我研究了一下,发现还是Ver命令最为成熟,为此综合各家做法写下了下面一个批处理文件: @echo off cls ver | find "4.0." > NUL && goto win95 ver | find "4.10." > NUL && goto win98 ver | find "

安卓开发:获取手机通讯录信息

写一个安卓软件,实现获取通讯录里的人名和对应的电话号码,并且通过ListView显示出来. 因为要获取手机本地的信息,所以第一个步骤就是先给定权限咯 <uses-permission android:name="android.permission.READ_CONTACTS"/> 因为获取到信息后是通过ListView显示出来,所以把布局写好,总共两个布局,一个布局放ListView,一个布局放ListView的子布局,这里比较基础,就不放代码了 接着就是通过java代码