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()

相关文章

处理Python中的URLError异常的方法

1.URLError 首先解释下URLError可能产生的原因:     网络无连接,即本机无法上网     连接不...

python Matplotlib画图之调整字体大小的示例

python Matplotlib画图之调整字体大小的示例

一张字体调整好的示例图: 字体大小就是 fontsize 参数 import matplotlib.pyplot as plt # 代码中的“...”代表省略的其他参数 ax =...

python读取文本中的坐标方法

利用python读取文本文件很方便,用到了string模块,下面用一个小例子演示读取文本中的坐标信息。 import string x , y , z = [] , [] ,[]...

Django数据库表反向生成实例解析

本文我们研究下如何在django中反向生成mysql model代码,接下来我们看看具体介绍。 我们在展示django ORM反向生成之前,我们先说一下怎么样正向生成代码。 正向生成,指...

在python3.5中使用OpenCV的实例讲解

在python3.5中使用OpenCV的实例讲解

最近在OpenCV的官方文档上看到一个人脸识别的示例代码,想要实现。由于我之前下好的OpenCV3.1中并不自带相关的函数,即opencv2/contrib/contrib.hpp这个文...