platform模块

 python中,platform模块给我们提供了很多方法去获取操作系统的信息
    如:
        import platform
        platform.platform()       # 获取操作系统名称及版本号,'Linux-3.13.0-46-generic-i686-with-Deepin-2014.2-trusty'
        platform.version()        # 获取操作系统版本号,'#76-Ubuntu SMP Thu Feb 26 18:52:49 UTC 2015'
        platform.architecture()   # 获取操作系统的位数,('32bit', 'ELF')
        platform.machine()        # 计算机类型,'i686'
        platform.node()           # 计算机的网络名称,'XF654'
        platform.processor()      # 计算机处理器信息,''i686'
        platform.uname()          # 包含上面所有的信息汇总,('Linux', 'XF654', '3.13.0-46-generic', '#76-Ubuntu SMP Thu Feb 26 18:52:49 UTC 2015', 'i686', 'i686')

        还可以获得计算机中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()



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





posted @ 2020-04-09 08:33  一颗桃子t  阅读(315)  评论(0编辑  收藏  举报