python 判断操作系统类型
1 #!/bin/python 2 # 3 import platform 4 5 def TestPlatform(): 6 print ("----------Operation System--------------------------") 7 #Windows will be : (32bit, WindowsPE) 8 #Linux will be : (32bit, ELF) 9 print(platform.architecture()) 10 11 #Windows will be : Windows-XP-5.1.2600-SP3 or Windows-post2008Server-6.1.7600 12 #Linux will be : Linux-2.6.18-128.el5-i686-with-redhat-5.3-Final 13 print(platform.platform()) 14 15 #Windows will be : Windows 16 #Linux will be : Linux 17 print(platform.system()) 18 19 print ("--------------Python Version-------------------------") 20 #Windows and Linux will be : 3.1.1 or 3.1.3 21 print(platform.python_version()) 22 23 def UsePlatform(): 24 sysstr = platform.system() 25 if(sysstr =="Windows"): 26 print ("Call Windows tasks") 27 elif(sysstr == "Linux"): 28 print ("Call Linux tasks") 29 else: 30 print ("Other System tasks") 31 32 UsePlatform()