python类型判断_Python 判断操作系统类型

获取操作系统类型

https://www.cndba.cn/laonanhai/article/2289https://www.cndba.cn/laonanhai/article/2289

https://www.cndba.cn/laonanhai/article/2289

http://www.cndba.cn/leo1990/article/1984

http://www.cndba.cn/leo1990/article/1984

https://www.cndba.cn/laonanhai/article/2289

https://www.cndba.cn/laonanhai/article/2289

https://www.cndba.cn/laonanhai/article/2289https://www.cndba.cn/laonanhai/article/2289https://www.cndba.cn/laonanhai/article/2289

代码如下:http://www.cndba.cn/leo1990/article/1984

https://www.cndba.cn/laonanhai/article/2289https://www.cndba.cn/laonanhai/article/2289

#!/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 执行

[root@localhost 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

[root@localhost 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值