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 与文件对象共事的实例

详解 Python 与文件对象共事的实例 Python 有一个内置函数,open,用来打开在磁盘上的文件。open 返回一个文件对象,它拥有一些方法和属性,可以得到被打开文件的信息,以及...

Python基于socket实现简单的即时通讯功能示例

本文实例讲述了Python基于socket实现简单的即时通讯功能。分享给大家供大家参考,具体如下: 客户端tcpclient.py # -*- coding: utf-8 -*- i...

python requests post多层字典的方法

pyhton requests模块post方法传参为多层字典时,转换错误, 如,表单传参 { “a”:1, “b”:{ “A”:2, “B”:3 } } post请求...

Django 开发环境配置过程详解

Django 开发环境配置过程详解

开发环境 开发环境为: Win 10(64位) Python 3.7.0 Django 2.1 安装Python python的安装为比较简单,首先找到Python官...

python与mysql数据库交互的实现

python与mysql数据库交互的实现

1、安装pymysql库 如果你想要使用python操作MySQL数据库,就必须先要安装pymysql库,这个库的安装很简单,直接使用pip install pymysql;进行安装。...