获取操作系统类型
代码如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import platform
def TestPlatform():
print ("----------Operation System--------------------------")
#Windows will be : ('64bit', 'WindowsPE')
#Linux will be : ('64bit', 'ELF')
print(platform.architecture())
#Windows will be : Windows-10-10.0.14393-SP0
#Linux will be : Linux-3.8.13-16.2.1.el6uek.x86_64-x86_64-with-redhat-6.5-Santiago
print(platform.platform())
#Windows will be : Windows
#Linux will be : Linux
print(platform.system())
print ("--------------Python Version-------------------------")
#Windows and Linux will be : 3.6.1 or 2.6.6
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")
if __name__ =='__main__':
TestPlatform()
UsePlatform()
代码保存在test.py 文件中分别在Linux 和 Windows 执行
[[email protected] test]# python test.py
----------Operation System--------------------------
('64bit', 'ELF')
Linux-3.8.13-16.2.1.el6uek.x86_64-x86_64-with-redhat-6.5-Santiago
Linux
--------------Python Version-------------------------
2.6.6
Call Linux tasks
[[email protected] test]# python test.py
----------Operation System--------------------------
('64bit', 'ELF')
Linux-3.8.13-16.2.1.el6uek.x86_64-x86_64-with-redhat-6.5-Santiago
Linux
--------------Python Version-------------------------
2.6.6
Call Linux tasks
E:/工作/test>python test.py
----------Operation System--------------------------
('64bit', 'WindowsPE')
Windows-10-10.0.14393-SP0
Windows
--------------Python Version-------------------------
3.6.1
Call Windows tasks
版权声明:本文为博主原创文章,未经博主允许不得转载。