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(' ...
随机推荐
- luogu P3919 【模板】可持久化数组(可持久化线段树/平衡树)
As you see // luogu-judger-enable-o2 #include<cstdio> #include<cstring> #include<algo ...
- [POJ1801]Formula Racing(模拟)
Formula Racing Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 289 Accepted: 77 Descr ...
- 1.4(Mybatis学习笔记)关联映射
一.一对一 mybatis处理一对一主要通过<resultMap>中的<association>元素来处理. <association>元素主要使用方方式有两种: ...
- Problem K: 数字菱形
#include<stdio.h> int main() { int n,i,j,k,t,x,q,p; while(scanf("%d",&n)!=EOF) ; ...
- 【MySQL笔记】MySql5安装图解教程
MySql5.6Window超详细安装教程 2015-06-23 0个评论 来源:林炳文Evankaka的专栏 收藏 我要投稿 一.安装包准备 1.下载MySql5.6 ht ...
- ListView(下)自定义适配器
(一) 1.效果图 2.activity_main.xml <?xml version="1.0" encoding="utf-8"?> <L ...
- nginx+php-fpm 报错Primary script unknown
报错信息(nginx日志): // :: [crit] #: * stat() : Permission denied), client: 172.21.205.25, server: localho ...
- java以流的形式输出文件
原文:http://blog.csdn.net/liutt55/article/details/78126614 public void downProcessFile(HttpServletRequ ...
- 【IntellJ IDEA】idea忽略隐藏文件、文件夹的设置操作
左上角setting 如果要忽略文件夹,则直接填写文件夹名字即可,例如:要忽略target文件夹[建议:尽量不要把target忽略,因为可能编译出问题排查,还需要查看target文件夹中的编译结果] ...
- C#远程获取图片文件流的方法【很通用】
因为之前写的代码,也能获取到图片流信息,但是会是凌乱的线条,后百度得这个方法,必须记录一下 C# try { WebRequest myrequest = WebRequest.Create(Http ...