Python判断操作系统类型代码分享

yipeiwu_com6年前Python基础

经常地我们需要编写跨平台的脚本,但是由于不同的平台的差异性,我们不得不获得当前所工作的平台(操作系统类型)。

代码如下:

复制代码 代码如下:

import platform

def TestPlatform():
    print ("----------Operation System--------------------------")
    #Windows will be : (32bit, WindowsPE)
    #Linux will be : (32bit, ELF)
    print(platform.architecture())

    #Windows will be : Windows-XP-5.1.2600-SP3 or Windows-post2008Server-6.1.7600
    #Linux will be : Linux-2.6.18-128.el5-i686-with-redhat-5.3-Final
    print(platform.platform())

    #Windows will be : Windows
    #Linux will be : Linux
    print(platform.system())

    print ("--------------Python Version-------------------------")
    #Windows and Linux will 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()

相关文章

Apache,wsgi,django 程序部署配置方法详解

Apache,wsgi,django 程序部署配置方法详解

本文实例讲述了Apache,wsgi,django 程序部署配置方法。分享给大家供大家参考,具体如下: 前面写过一篇文章,ngixn,uwsgi,django,python 环境配置,有...

python multiprocessing模块用法及原理介绍

一 multiprocessing模块介绍 python中的多线程无法利用多核优势,如果想要充分地使用多核CPU的资源(os.cpu\_count\(\)查看),在python中大部分...

Python处理RSS、ATOM模块FEEDPARSER介绍

由于Google reader的关闭,这段时间接触rss的东西相对多很多。试过qq的reader,不怎么样,阅读速度没有,是否阅读的标记也没有。其他网站的不想用,又要多注册账户。 找到p...

使用PIL(Python-Imaging)反转图像的颜色方法

利用PIL将图片转换为黑色与白色反转的图片,下面笔者小白介绍如何实现。 解决方案一: from PIL import Image import PIL.ImageOps #读入图...

Python使用time模块实现指定时间触发器示例

Python使用time模块实现指定时间触发器示例

本文实例讲述了Python使用time模块实现指定时间触发器。分享给大家供大家参考,具体如下: 其实很简单,指定某个时间让脚本处理一个事件,比如说一个get请求~ 任何语言都会有关于时间...