签到成功

知道了

CNDBA社区CNDBA社区

python 判断操作系统类型

2017-06-12 23:27 2515 0 原创 Python
作者: leo

获取操作系统类型http://www.cndba.cn/leo1990/article/1984http://www.cndba.cn/leo1990/article/1984http://www.cndba.cn/leo1990/article/1984

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

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

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

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

版权声明:本文为博主原创文章,未经博主允许不得转载。

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
leo

leo

关注

坚持你的坚持

  • 202
    原创
  • 0
    翻译
  • 39
    转载
  • 16
    评论
  • 访问:765921次
  • 积分:1270
  • 等级:核心会员
  • 排名:第8名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ