python-Obtaining operating System Information

Source: Internet
Author: User

#!/usr/bin/env python#-*-coding:utf-8-*-#############################File Name:test_platform.py#Author:frank#Mail: [email protected]#Created time:2017-06-05 14:31:31############################ImportPlatform OS=Platform.system ()PrintOSPrintPlatform.platform ()Printplatform.version ()Printplatform.architecture ()" " Python, the platform module gives us a lot of ways to get information about the operating system such as: Import Platform PLATFORM.PLATF ORM () #获取操作系统名称及版本号, ' Linux-3.13.0-46-generic-i686-with-deepin-2014.2-trusty ' platform.version () #获        Take the operating system version number, ' #76-ubuntu SMP Thu Feb 18:52:49 UTC ' platform.architecture () #获取操作系统的位数, (' 32bit ', ' ELF ')        Platform.machine () #计算机类型, ' i686 ' Platform.node () #计算机的网络名称, ' XF654 ' platform.processor () #计算机处理器信息, ' i686 ' Platform.uname () #包含上面所有的信息汇总, (' Linux ', ' XF654 ', ' 3.13.0-46-generic ', ' #76-ubunt U SMP Thu Feb 18:52:49 UTC ", ' i686 ', ' i686 ') You can also get some information about Python in your computer: Import platform PLATFORM.P        Ython_build () Platform.python_compiler () Platform.python_branch () platform.python_implementation () Platform.python_revision () platform.python_version () platform.python_version_tuple () " "#Global Var#whether to display log informationShow_log =Truedefget_platform ():" "get the operating system name and version number" "    returnPlatform.platform ()defget_version ():" "get the operating system version number" "    returnplatform.version ()defget_architecture ():" "get the number of bits in the operating system" "    returnplatform.architecture ()defget_machine ():" "Computer Type" "    returnPlatform.machine ()defGet_node ():" "the network name of the computer" "    returnPlatform.node ()defget_processor ():" "Computer processor Information" "    returnplatform.processor ()defGet_system ():" "get operating system type" "    returnPlatform.system ()defget_uname ():" "Summary Information" "    returnPlatform.uname ()defget_python_build ():" "The Python build number and date as strings" "    returnPlatform.python_build ()defGet_python_compiler ():" "Returns A string identifying the compiler used for compiling Python" "    returnPlatform.python_compiler ()defget_python_branch ():" "Returns A string identifying the Python implementation SCM Branch" "    returnPlatform.python_branch ()defget_python_implementation ():" "Returns A string identifying the Python implementation. Possible return values are: ' CPython ', ' IronPython ', ' Jython ', ' pypy '." "    returnplatform.python_implementation ()defget_python_version ():" "Returns the Python version as String ' Major.minor.patchlevel '" "    returnplatform.python_version ()defget_python_revision ():" "Returns A string identifying the Python implementation SCM revision." "    returnplatform.python_revision ()defget_python_version_tuple ():" "Returns the Python version as tuple (major, minor, patchlevel) of strings" "    returnplatform.python_version_tuple ()defshow_os_all_info ():" "Print all information about the OS" "    Print('get the operating system name and version number: [{}]'. Format (Get_platform ()))Print('get operating system version number: [{}]'. Format (get_version ()))Print('get the number of bits of the operating system: [{}]'. Format (Get_architecture ()))Print('computer type: [{}]'. Format (Get_machine ()))Print('Computer's network name: [{}]'. Format (Get_node ()))Print('Computer processor information: [{}]'. Format (Get_processor ()))Print('get operating system type: [{}]'. Format (Get_system ()))Print('summary information: [{}]'. Format (Get_uname ()))defshow_os_info ():" "Print only OS information, no explanation section" "    Print(Get_platform ())Print(Get_version ())Print(Get_architecture ())Print(Get_machine ())Print(Get_node ())Print(Get_processor ())Print(Get_system ())Print(Get_uname ())defshow_python_all_info ():" "Print all of Python's information" "    Print('The Python build number and date as strings: [{}]'. Format (Get_python_build ()))Print('Returns A string identifying the compiler used for compiling Python: [{}]'. Format (Get_python_compiler ()))Print('Returns A string identifying the Python implementation SCM Branch: [{}]'. Format (Get_python_branch ()))Print('Returns A string identifying the Python implementation: [{}]'. Format (Get_python_implementation ()))Print('The version of Python: [{}]'. Format (Get_python_version ()))Print('Python Implementation SCM revision: [{}]'. Format (Get_python_revision ()))Print('Python version as tuple: [{}]'. Format (Get_python_version_tuple ()))defshow_python_info ():" "Print only Python information, no explanation part" "    Print(Get_python_build ())Print(Get_python_compiler ())Print(Get_python_branch ())Print(Get_python_implementation ())Print(Get_python_version ())Print(Get_python_revision ())Print(Get_python_version_tuple ())defTest ():Print('Operating System Information:')    ifShow_log:show_os_all_info ()Else: Show_os_info ()Print('#'* 50)    Print('python information in the computer:')    ifShow_log:show_python_all_info ()Else: Show_python_info ()definit ():GlobalShow_log Show_log=TruedefMain (): Init () test ()if __name__=='__main__': Main ()

python-Obtaining operating System Information

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.