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

相关文章

pyqt5实现登录界面的模板

本文实例为大家分享了pyqt5登录界面的实现模板,供大家参考,具体内容如下 说明 本例,展示了通过登录界面打开主界面的实现方式。 其中,登录的账号与密码判断都比较简单,请大家根据自己需...

Windows下pycharm创建Django 项目(虚拟环境)过程解析

Windows下pycharm创建Django 项目(虚拟环境)过程解析

1. 背景 我在 Windows 下的 pycharm 直接创建 全新 Django 项目 会 pip 和其他报错 ,暂时解决不了,另外后续的多个项目只需要一套python 环境, 所以...

Python使用PyCrypto实现AES加密功能示例

本文实例讲述了Python使用PyCrypto实现AES加密功能。分享给大家供大家参考,具体如下: #!/usr/bin/env python from Crypto.Cipher...

Python完全新手教程

Python入门教程Lesson 1 准备好学习Python的环境 下载的地址是: www.python.org linux版本的我就不说了,因为如果你能够使用linu...

Pytorch在NLP中的简单应用详解

Pytorch在NLP中的简单应用详解

因为之前在项目中一直使用Tensorflow,最近需要处理NLP问题,对Pytorch框架还比较陌生,所以特地再学习一下pytorch在自然语言处理问题中的简单使用,这里做一个记录。 一...