Code sharing for determining operating system types in Python

Source: Internet
Author: User
This article mainly introduces how to use Python to determine the type of operating system code. it is often used to compile cross-platform programs. For more information, see cross-platform scripts, however, due to the differences between different platforms, we have to obtain the platform (operating system type) currently working ).

The code is as follows:

The code is as follows:


Import platform

Def TestPlatform ():
Print ("---------- Operation System --------------------------")
# Windows will be: (32bit, WindowsPE)
# Linux will be: (32bit, ELF)
Print (platform. architecture ())

# Windows will be: Windows-XP-5.1.2600-SP3 or Windows-post2008Server-6.1.7600
# Linux will be: Linux-2.6.18-128.el5-i686-with-redhat-5.3-Final
Print (platform. platform ())

# Windows will be: Windows
# Linux will be: Linux
Print (platform. system ())

Print ("-------------- Python Version -------------------------")
# Windows and Linux will be: 3.1.1 or 3.1.3
Print (platform. python_version ())

Def UsePlatform ():
Sysstr = platform. system ()
If (sysstr = "Windows "):
Print ("Call Windows tasks ")
Elif (sysstr = "Linux "):
Print ("Call Linux tasks ")
Else:
Print ("Other System tasks ")

UsePlatform ()

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.