python-获取操作系统信息
#!/usr/bin/env python
#-*- coding:utf-8 -*-
############################
#File Name: test_platform.py
#Author: frank
#Mail: frank0903@aliyun.com
#Created Time:2017-06-05 14:31:31
############################ import platform
os = platform.system()
print os
print platform.platform()
print platform.version()
print platform.architecture() '''
python中,platform模块给我们提供了很多方法去获取操作系统的信息
如:
import platform
platform.platform() #获取操作系统名称及版本号,'Linux-3.13.0-46-generic-i686-with-Deepin-2014.2-trusty'
platform.version() #获取操作系统版本号,'#76-Ubuntu SMP Thu Feb 26 18:52:49 UTC 2015'
platform.architecture() #获取操作系统的位数,('32bit', 'ELF')
platform.machine() #计算机类型,'i686'
platform.node() #计算机的网络名称,'XF654'
platform.processor() #计算机处理器信息,''i686'
platform.uname() #包含上面所有的信息汇总,('Linux', 'XF654', '3.13.0-46-generic', '#76-Ubuntu SMP Thu Feb 26 18:52:49 UTC 2015', 'i686', 'i686') 还可以获得计算机中python的一些信息:
import platform
platform.python_build()
platform.python_compiler()
platform.python_branch()
platform.python_implementation()
platform.python_revision()
platform.python_version()
platform.python_version_tuple()
''' #global var
#是否显示日志信息
SHOW_LOG = True def get_platform():
'''获取操作系统名称及版本号'''
return platform.platform() def get_version():
'''获取操作系统版本号'''
return platform.version() def get_architecture():
'''获取操作系统的位数'''
return platform.architecture() def get_machine():
'''计算机类型'''
return platform.machine() def get_node():
'''计算机的网络名称'''
return platform.node() def get_processor():
'''计算机处理器信息'''
return platform.processor() def get_system():
'''获取操作系统类型'''
return platform.system() def get_uname():
'''汇总信息'''
return platform.uname() def get_python_build():
''' the Python build number and date as strings'''
return platform.python_build() def get_python_compiler():
'''Returns a string identifying the compiler used for compiling Python'''
return platform.python_compiler() def get_python_branch():
'''Returns a string identifying the Python implementation SCM branch'''
return platform.python_branch() def get_python_implementation():
'''Returns a string identifying the Python implementation. Possible return values are: ‘CPython’, ‘IronPython’, ‘Jython’, ‘PyPy’.'''
return platform.python_implementation() def get_python_version():
'''Returns the Python version as string 'major.minor.patchlevel'
'''
return platform.python_version() def get_python_revision():
'''Returns a string identifying the Python implementation SCM revision.'''
return platform.python_revision() def get_python_version_tuple():
'''Returns the Python version as tuple (major, minor, patchlevel) of strings'''
return platform.python_version_tuple() def show_os_all_info():
'''打印os的全部信息'''
print('获取操作系统名称及版本号 : [{}]'.format(get_platform()))
print('获取操作系统版本号 : [{}]'.format(get_version()))
print('获取操作系统的位数 : [{}]'.format(get_architecture()))
print('计算机类型 : [{}]'.format(get_machine()))
print('计算机的网络名称 : [{}]'.format(get_node()))
print('计算机处理器信息 : [{}]'.format(get_processor()))
print('获取操作系统类型 : [{}]'.format(get_system()))
print('汇总信息 : [{}]'.format(get_uname())) def show_os_info():
'''只打印os的信息,没有解释部分'''
print(get_platform())
print(get_version())
print(get_architecture())
print(get_machine())
print(get_node())
print(get_processor())
print(get_system())
print(get_uname()) def show_python_all_info():
'''打印python的全部信息'''
print('The Python build number and date as strings : [{}]'.format(get_python_build()))
print('Returns a string identifying the compiler used for compiling Python : [{}]'.format(get_python_compiler()))
print('Returns a string identifying the Python implementation SCM branch : [{}]'.format(get_python_branch()))
print('Returns a string identifying the Python implementation : [{}]'.format(get_python_implementation()))
print('The version of Python : [{}]'.format(get_python_version()))
print('Python implementation SCM revision : [{}]'.format(get_python_revision()))
print('Python version as tuple : [{}]'.format(get_python_version_tuple())) def show_python_info():
'''只打印python的信息,没有解释部分'''
print(get_python_build())
print(get_python_compiler())
print(get_python_branch())
print(get_python_implementation())
print(get_python_version())
print(get_python_revision())
print(get_python_version_tuple()) def test():
print('操作系统信息:')
if SHOW_LOG:
show_os_all_info()
else:
show_os_info()
print('#' * 50)
print('计算机中的python信息:')
if SHOW_LOG:
show_python_all_info()
else:
show_python_info() def init():
global SHOW_LOG
SHOW_LOG = True def main():
init()
test() if __name__ == '__main__':
main()
python-获取操作系统信息的更多相关文章
- 使用 python 获取 Linux 系统信息(通过dmidecode命令)
通过 dmidecode 命令可以获取到 Linux 系统的包括 BIOS. CPU.内存等系统的硬件信息,这里使用 python 代码来通过调用 dmidecode 命令来获取 Linux 必要的系 ...
- 使用 Python 获取 Linux 系统信息
探索platform模块 platform模块在标准库中,它有很多运行我们获得众多系统信息的函数.让我们运行Python解释器来探索它们中的一些函数,那就从platform.uname()函数开始吧: ...
- 【转】 使用 Python 获取 Linux 系统信息
在本文中,我们将会探索使用Python编程语言工具来检索Linux系统各种信息.走你. 哪个Python版本? 当我提及Python,所指的就是CPython 2(准确的是2.7).我会显式提醒那些相 ...
- Java获取操作系统信息
今天在看jdk的demo时候发现java获取系统操作系统的一些信息,例如内存使用情况,于是自己也想研究研究! 百度一番,发现有2种方法! 1.sun自带的API 2.第三方jar(Sigar) 先 ...
- php获取客户端浏览器以及操作系统信息的方法
发布:sunday01 来源:net 阅读: 2 [大 中 小] 在较为智能的程序中,php可以获取客户端浏览器及操作系统信息,然后根据浏览器及系统类型,加载不同的页面,以提供更加个性化的 ...
- java web 获取客户端操作系统信息
package com.java.basic.pattern; import java.util.regex.Matcher; import java.util.regex.Pattern; /** ...
- python获取系统信息psutil
python获取系统信息psutil:psutil获取系统cpu使用率的方法是cpu_percent(),其有两个参数,分别是interval和percpu,interval指定的是计算cpu使用率的 ...
- C# 获取计算机的硬件、操作系统信息
C# 获取计算机的硬件.操作系统信息 获得信息的命名空间是:System.Management 创建ManagementObjectSearcher对象获取相关信息 eg: using Syste ...
- 用python获取服务器硬件信息[转]
#!/usr/bin/env python # -*- coding: utf-8 -*- import rlcompleter, readline readline.parse_and_bind(' ...
随机推荐
- HTML5 Boilerplate笔记(3)
HTML5 Boilerplate项目网址:https://github.com/h5bp/html5-boilerplate
- jQuery判断一个元素是否为另一个元素的子元素
判断:当前元素是否是被筛选元素的子元素 jQuery.fn.isChildOf = function(b){ return (this.parents(b).length > 0); }; 判断 ...
- ubuntu下python3及idle3的安装
一.使用以下命令检查自己的系统下是否有python3 python3 --version 如果出现类似“command not found",则说明你需要安装python3.如果能够出现py ...
- Java使用POM一JAR包的形式管理JavaScript文件-WebJars
说明:原来JS框架还可以使用POM进行管理的.WebJars是一个很神奇的东西,可以让大家以JAR包的形式来使用前端的各种框架.组件. 什么是WebJars 什么是WebJars?WebJars是将客 ...
- C# 6.0语法新特性体验(二)
之前我在文章通过Roslyn体验C# 6.0的新语法中介绍了一些C# 6.0的语法特性,现在随着Visual Studio 14 CTP3的发布,又陆续可以体验一些新的特性了,这里简单的介绍一下之前没 ...
- 扑克模拟,牌型判断java版
Card类 package com.company; public class Card { private String color; private Integer value; public S ...
- Solr6.6 配置中文分词库mmseg4j
1.准备 首先安装solr:参照搜索引擎Solr-6.6.0搭建,如果版本高于6,可能会不支持,需要改mmseg4j包 mmseg4j包下载: mmseg4j-solr-2.3.0-with-mmse ...
- socket编程演示样例(多线程)
client代码例如以下: import java.io.*; import java.net.*; import java.util.Scanner; public class SimpleChat ...
- 让Qt Creator支持Windows Phone 8开发
让Qt Creator支持Windows Phone 8开发 近期QtCreator3.2出了.修复了一些Bug.比上一个版本号3.1.2要好了一些. 因为在上一个版本号(Qt for WinRT自带 ...
- C#秘密武器之LINQ to SQL
LINQ to SQL语句(1)之Where 适用场景:实现过滤,查询等功能. 说明:与SQL命令中的Where作用相似,都是起到范围限定也就是过滤作用的,而判断条件就是它后面所接的子句.Where操 ...