Python Judge OS type code sharing _python

Source: Internet
Author: User

Often we need to write cross-platform scripts, but due to the diversity of different platforms, we have to get the platform (OS type) we are working on.

The code is as follows:

Copy Code code as follows:

Import Platform

Def testplatform ():
Print ("----------Operation System--------------------------")
#Windows would be: (32bit, WindowsPE)
#Linux would be: (32bit, ELF)
Print (Platform.architecture ())

#Windows would be:windows-xp-5.1.2600-sp3 or windows-post2008server-6.1.7600
#Linux would be:linux-2.6.18-128.el5-i686-with-redhat-5.3-final
Print (Platform.platform ())

#Windows would be:windows
#Linux would be:linux
Print (Platform.system ())

Print ("--------------Python Version-------------------------")
#Windows and Linux would 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.