参考文献:http://bbs.chinaunix.net/thread-1848086-1-1.html

经常地我们需要编写跨平台的脚本,但是由于不同的平台的差异性,我们不得不获得当前所工作的平台(操作系统类型)。

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()//方法1
TestPlatform()//方法2

我安装了python以后,使用python GUI打开以后执行上述方法,其输出结果如下图所示。

python实例[判断操作系统类型]的更多相关文章

  1. Java 判断操作系统类型(适用于各种操作系统)

    Java 判断操作系统类型(适用于各种操作系统) 最近一段时间写一个授权的程序,需要获取很多信息来保证程序不能随意复制使用,必须经过授权才可以. 为了限制用户使用的操作系统,必须有统一的方法来获取才可 ...

  2. 深入C#判断操作系统类型的总结详解(转载)

    Windows操作系统的版本号一览 操作系统  PlatformID  主版本号  副版本号  Windows95  1  4  0  Windows98  1  4  10  WindowsMe   ...

  3. C#判断操作系统类型汇总

    Windows操作系统的版本号一览 操作系统 PlatformID 主版本号 副版本号 Windows95 1 4 0 Windows98 1 4 10 WindowsMe 1 4 90 Window ...

  4. python准确判断文件类型

    判断文件类型在开发中非常常见的需求,怎样才能准确的判断文件类型呢?首先大家想到的是文件的后缀,但是非常遗憾的是这种方法是非常不靠谱的,因为文件的后缀是可以随意更改的,而大家都知道后缀在linux系统下 ...

  5. python,判断操作系统是windows,linux

    import sys,platform print(sys.platform) print(platform.system()) sys.platform: 获取当前系统平台. platform.sy ...

  6. python 判断操作系统类型

    #!/bin/python # import platform def TestPlatform(): print ("----------Operation System--------- ...

  7. Python判断操作系统类型

    代码: import platform def TestPlatform(): print ("----------Operation System--------------------- ...

  8. python中判断对象类型的函数——isinstance

    isinstance是Python中的一个内建函数.是用来判断一个对象的变量类型. isinstance(object, class-or-type-or-tuple) 如果参数object是clas ...

  9. python isinstance 判断各种类型的小细节

    1. 基本语法 isinstance(object, classinfo) Return true if the object argument is an instance of the class ...

随机推荐

  1. [R语言]关联规则2---考虑items之间严格的时序关系

    前面介绍了关联规则1---不考虑用户购买的items之间的时序关系,但在一些情况下用户购买item是有严格的次序关系了,比如在某些休闲游戏中,用户购买了道具A才能购买道具B,且道具A和B只能购买一次, ...

  2. Ubuntu 查看CPU温度

    按照这篇文章: http://www.webupd8.org/2014/06/psensor-updated-with-option-to-display.html

  3. 使用 jquery-autocomplete插件 完成文本框输入自动填充联想效果 解决兼容IE输入中文问题

    项目中有时会用到ajax自动补全查询,就像Google的搜索框中那样,输入汉字或者字母的首个字母,则包含这个汉字或者字母的相关条目会显示出来供用户选择,该插件就是实现这样的功能的.autocomple ...

  4. react-native 报错

    报错信息: java.lang.RuntimeException: Unable to load script from assets 'index.android.bundle'. Make sur ...

  5. Excel学习笔记:vlookup基础及多条件查找

    一.vlookup基础 关于vlookup的基础不多记录,相信基本的使用方法大家都懂得. 使用格式:=vlookup(搜索值,搜索范围,列号,是否精准匹配) =VLOOKUP(E2,$B$2:$C$6 ...

  6. printf 字符串格式

    摘自:http://www.cppblog.com/API/archive/2013/07/18/201923.html 首先 long long是C99标准新规定的.不少编译器还不支持,Micros ...

  7. ssh登录,Host key verification failed的几种处理方法

    - 修订历史History:  2011.05.22   初稿 - 系统: Ubuntu 10.04LTS  - 软件: SSH 使用SSH登录某台机器,有时因为server端的一些变动,会出现以下信 ...

  8. Simple Web API Server in Golang (2)

    In this challenge, I tried to implement a simple OAuth2 server basing on Simple Web API Server in [1 ...

  9. word2vec中的数学原理一 目录和前言

    最近在看词向量了,因为这个概念对于语言模型,nlp都比较重要,要好好的学习一下.把网上的一些资料整合一下,搞个系列. 主要参考:    word2vec 中的数学原理详解                ...

  10. UI 框架

    Vue.js 之 iView UI 框架 像我们平日里做惯了 Java 或者 .NET 这种后端程序员,对于前端的认识还常常停留在 jQuery 时代,包括其插件在需要时就引用一下,不需要就删除.故观 ...