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

相关文章

pyqt5、qtdesigner安装和环境设置教程

pyqt5、qtdesigner安装和环境设置教程

前言 最近工作需要写一个界面程序来调用摄像头并对摄像头采集的图像做一些处理。程序需要使用Python语言编写,经过调研发现PyQt5配合QtDesigner在界面程序编写方面具有功能丰富...

解决python彩色螺旋线绘制引发的问题

解决python彩色螺旋线绘制引发的问题

彩色螺旋线的绘制代码如下: import turtle import time turtle.pensize(2) turtle.bgcolor('black') colors =...

python并发2之使用asyncio处理并发

python并发2之使用asyncio处理并发

asyncio 在Python 2的时代,高性能的网络编程主要是使用Twisted、Tornado和Gevent这三个库,但是它们的异步代码相互之间既不兼容也不能移植。如上一节说的,G...

Python骚操作之动态定义函数

在 Python 中,没有可以在运行时简化函数定义的语法糖。然而,这并不意味着它就不可能,或者是难以实现。 from types import FunctionType foo_c...

Python实现的企业粉丝抽奖功能示例

Python实现的企业粉丝抽奖功能示例

本文实例讲述了Python实现的企业粉丝抽奖功能。分享给大家供大家参考,具体如下: 一 代码 def scode9(schoice): default_dir = r"lotte...