• python之platform模块


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

    Windows
    操作系统信息:
    获取操作系统名称及版本号 : [Windows-7-6.1.7601-SP1]
    获取操作系统版本号 : [6.1.7601]
    获取操作系统的位数 : [('32bit', 'WindowsPE')]
    计算机类型 : [AMD64]
    计算机的网络名称 : [dw2019]
    计算机处理器信息 : [Intel64 Family 6 Model 69 Stepping 1, GenuineIntel]
    获取操作系统类型 : [Windows]
    汇总信息 : [uname_result(system='Windows', node='dw2019', release='7', version='6.1.7601', machine='AMD64', processor='Intel64 Family 6 Model 69 Stepping 1, GenuineIntel')]
    ##################################################
    计算机中的python信息:
    The Python build number and date as strings : [('v3.3.3:c3896275c0f6', 'Nov 18 2013 21:18:40')]
    Returns a string identifying the compiler used for compiling Python : [MSC v.1600 32 bit (Intel)]
    Returns a string identifying the Python implementation SCM branch : [v3.3.3]
    Returns a string identifying the Python implementation : [CPython]
    The version of Python : [3.3.3]
    Python implementation SCM revision : [c3896275c0f6]
    Python version as tuple : [('3', '3', '3')]

    参考大神总结:https://blog.csdn.net/xc_tsao/article/details/44007143

  • 相关阅读:
    触屏时间控制
    小程序 坐标算距离 (copy)
    微信小程序 对接口常用
    conversion function to_char to_number
    南通
    日期 function
    数字 function
    字符串处理函数
    沪通铁路1
    NVL NVL2 COALESCE NULLIF decode
  • 原文地址:https://www.cnblogs.com/magic-dw/p/13669656.html
Copyright © 2020-2023  润新知