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