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

yipeiwu_com5年前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()

相关文章

在Python的Django框架中调用方法和处理无效变量

方法调用行为 方法调用比其他类型的查找略为复杂一点。 以下是一些注意事项:     在方法查找过程中,如果某方法抛出一个异常,除非该异常有一个 silent...

django-rest-framework 自定义swagger过程详解

django-rest-framework 自定义swagger过程详解

前言 之前的文章编写了一个返回json的例子,直接用浏览器进行get请求虽然成功了, 但是接口文档的样式很难看, 不好用. 而且提示没有访问权限. 我们一般都希望能够直接在接口文档中...

Python实现求一个集合所有子集的示例

方法一:回归实现 def PowerSetsRecursive(items): """Use recursive call to return all subsets of it...

python读取视频流提取视频帧的两种方法

本文实例为大家分享了python读取视频流提取视频帧的具体代码,供大家参考,具体内容如下 方法一:通过imageio库和skimage库 1. 安装环境: pip install ima...

Python Socket编程之多线程聊天室

Python Socket编程之多线程聊天室

本文为大家分享了Python多线程聊天室,是一个Socket,两个线程,一个是服务器,一个是客户端。 最近公司培训,要写个大富翁的小程序,准备做个服务器版的,先练练手。 代码: #...