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 ()