#!/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-获取操作系统信息的更多相关文章

  1. 使用 python 获取 Linux 系统信息(通过dmidecode命令)

    通过 dmidecode 命令可以获取到 Linux 系统的包括 BIOS. CPU.内存等系统的硬件信息,这里使用 python 代码来通过调用 dmidecode 命令来获取 Linux 必要的系 ...

  2. 使用 Python 获取 Linux 系统信息

    探索platform模块 platform模块在标准库中,它有很多运行我们获得众多系统信息的函数.让我们运行Python解释器来探索它们中的一些函数,那就从platform.uname()函数开始吧: ...

  3. 【转】 使用 Python 获取 Linux 系统信息

    在本文中,我们将会探索使用Python编程语言工具来检索Linux系统各种信息.走你. 哪个Python版本? 当我提及Python,所指的就是CPython 2(准确的是2.7).我会显式提醒那些相 ...

  4. Java获取操作系统信息

    今天在看jdk的demo时候发现java获取系统操作系统的一些信息,例如内存使用情况,于是自己也想研究研究! 百度一番,发现有2种方法! 1.sun自带的API 2.第三方jar(Sigar)   先 ...

  5. php获取客户端浏览器以及操作系统信息的方法

    发布:sunday01   来源:net   阅读: 2   [大 中 小] 在较为智能的程序中,php可以获取客户端浏览器及操作系统信息,然后根据浏览器及系统类型,加载不同的页面,以提供更加个性化的 ...

  6. java web 获取客户端操作系统信息

    package com.java.basic.pattern; import java.util.regex.Matcher; import java.util.regex.Pattern; /** ...

  7. python获取系统信息psutil

    python获取系统信息psutil:psutil获取系统cpu使用率的方法是cpu_percent(),其有两个参数,分别是interval和percpu,interval指定的是计算cpu使用率的 ...

  8. C# 获取计算机的硬件、操作系统信息

    C# 获取计算机的硬件.操作系统信息   获得信息的命名空间是:System.Management 创建ManagementObjectSearcher对象获取相关信息 eg: using Syste ...

  9. 用python获取服务器硬件信息[转]

    #!/usr/bin/env python # -*- coding: utf-8 -*- import rlcompleter, readline readline.parse_and_bind(' ...

随机推荐

  1. Codeforces 915 E Physical Education Lessons

    题目描述 This year Alex has finished school, and now he is a first-year student of Berland State Univers ...

  2. POJ 2559 Largest Rectangle in a Histogram(单调栈)

    [题目链接] http://poj.org/problem?id=2559 [题目大意] 给出一些宽度为1的长方形下段对其后横向排列得到的图形,现在给你他们的高度, 求里面包含的最大长方形的面积 [题 ...

  3. 【枚举】Codeforces Round #394 (Div. 2) C. Dasha and Password

    纪念死去的智商(虽然本来就没有吧……) 三重循环枚举将哪三个fix string作为数字.字母和符号位.记下最小的值就行了. 预处理之后这个做法应该是O(n^3)的,当然完全足够.不预处理是O(n^3 ...

  4. Exercise01_11

    public class Population{ public static void main(String[] args){ int sum,s; s=365*5*24*60*60; sum=31 ...

  5. 动态OSPF配置路由表

    动态ospf设置路由表 以Rourer1为例子 (1)首先设置路由器端口ip Router(config)#inter f0/0 Router(config-if)#ip add 192.168.1. ...

  6. UILabel设置行间距

    UILabel设置行间距: NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWi ...

  7. htc支持CSS3

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...

  8. 针对WebLogic Server 12.1.3版本打补丁

    先去下载补丁文件,在链接 https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=179118524484876&id= ...

  9. CSS 布局模型

    css布局模型 布局模型与盒模型一样都是 CSS 最基本. 最核心的概念. 但布局模型是建立在盒模型基础之上.又不同于我们常说的 CSS 布局样式或 CSS 布局模板.假设说布局模型是本.那么 CSS ...

  10. ylbtech-LanguageSamples-Events(事件)

    ylbtech-Microsoft-CSharpSamples:ylbtech-LanguageSamples-Events(事件) 1.A,示例(Sample) 返回顶部 “事件”示例 本示例演示如 ...