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切换pip安装源的方法详解

Python切换pip安装源的方法详解

一、pip简介 Pip 是安装python包的工具,提供了安装包,列出已经安装的包,升级包以及卸载包的功能。 Pip 是对easy_install的取代,提供了和easy_install...

DataFrame 将某列数据转为数组的方法

如下所示: playerIds =salaries_2016['playerID'].tolist() data['列名'].tolist() 以上这篇DataFrame 将某列...

Python使用numpy模块实现矩阵和列表的连接操作方法

Numpy模块被广泛用于科学和数值计算,自然有它的强大之处,之前对于特征处理中需要进行数据列表或者矩阵拼接的时候都是自己写的函数来完成的,今天发现一个好玩的函数,不仅好玩,关键性能强大,...

python单例设计模式实现解析

python单例设计模式实现解析

这篇文章主要介绍了python单例设计模式实现解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 所谓单例,就是让类创建对象的时候,在...

python变量不能以数字打头详解

在编写python函数时,无意中发现一个问题:python中的变量不能以数字打头,以下函数中定义了一个变量3_num_varchar,执行时报错。 函数如下: def databas...