python利用platform模块获取系统信息


Posted in Python onOctober 09, 2020

Python platform 模块

platform 模块用于查看当前操作系统的信息,来采集系统版本位数计算机类型名称内核等一系列信息。

使用方法:

#coding:utf-8

import platform

t=platform.system()
print(t)



#coding=utf-8

#platform_mode.py

import platform

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

Windows
操作系统信息:
获取操作系统名称及版本号 : [Windows-7-6.1.7601-SP1]
获取操作系统版本号 : [6.1.7601]
获取操作系统的位数 : [('32bit', 'WindowsPE')]
计算机类型 : [AMD64]
计算机的网络名称 : [dw2019]
计算机处理器信息 : [Intel64 Family 6 Model 69 Stepping 1, GenuineIntel]
获取操作系统类型 : [Windows]
汇总信息 : [uname_result(system='Windows', node='dw2019', release='7', version='6.1.7601', machine='AMD64', processor='Intel64 Family 6 Model 69 Stepping 1, GenuineIntel')]
##################################################
计算机中的python信息:
The Python build number and date as strings : [('v3.3.3:c3896275c0f6', 'Nov 18 2013 21:18:40')]
Returns a string identifying the compiler used for compiling Python : [MSC v.1600 32 bit (Intel)]
Returns a string identifying the Python implementation SCM branch : [v3.3.3]
Returns a string identifying the Python implementation : [CPython]
The version of Python : [3.3.3]
Python implementation SCM revision : [c3896275c0f6]
Python version as tuple : [('3', '3', '3')]

以上就是python利用platform模块获取系统信息的详细内容,更多关于Python platform 模块的资料请关注三水点靠木其它相关文章!

Python 相关文章推荐
Python中的字典遍历备忘
Jan 17 Python
python读取excel表格生成erlang数据
Aug 26 Python
基于Django contrib Comments 评论模块(详解)
Dec 08 Python
python 计算数组中每个数字出现多少次--“Bucket”桶的思想
Dec 19 Python
python代码实现ID3决策树算法
Dec 20 Python
Python读取MRI并显示为灰度图像实例代码
Jan 03 Python
python list元素为tuple时的排序方法
Apr 18 Python
python计算日期之间的放假日期
Jun 05 Python
python列表推导式入门学习解析
Dec 02 Python
浅谈图像处理中掩膜(mask)的意义
Feb 19 Python
浅谈django不使用restframework自定义接口与使用的区别
Jul 15 Python
Selenium环境变量配置(火狐浏览器)及验证实现
Dec 07 Python
python smtplib发送多个email联系人的实现
Oct 09 #Python
python 决策树算法的实现
Oct 09 #Python
Python+unittest+requests 接口自动化测试框架搭建教程
Oct 09 #Python
Python实现http接口自动化测试的示例代码
Oct 09 #Python
python两种注释用法的示例
Oct 09 #Python
Python实现扫码工具的示例代码
Oct 09 #Python
如何完美的建立一个python项目
Oct 09 #Python
You might like
PHP操作MongoDB时的整数问题及对策说明
2011/05/02 PHP
百度实时推送api接口应用示例
2014/10/21 PHP
ThinkPHP有变量的where条件分页实例
2014/11/03 PHP
PHP实现抓取Google IP并自动修改hosts文件
2015/02/12 PHP
php表单文件iframe异步上传实例讲解
2017/07/26 PHP
在 PHP 和 Laravel 中使用 Traits的方法
2019/11/13 PHP
通过Mootools 1.2来操纵HTML DOM元素
2009/09/15 Javascript
javascript自启动函数的问题探讨
2013/10/05 Javascript
使用delegate方法为一个tr标签加一个链接
2014/06/27 Javascript
JavaScript中的null和undefined区别介绍
2015/01/01 Javascript
JS返回只包含数字类型的数组实例分析
2016/12/16 Javascript
解决Node.js使用MySQL出现connect ECONNREFUSED 127.0.0.1:3306的问题
2017/03/09 Javascript
jQuery实现表格冻结顶栏效果
2017/08/20 jQuery
js求数组中全部数字可拼接出的最大整数示例代码
2017/08/25 Javascript
JS+canvas绘制的动态机械表动画效果
2017/09/12 Javascript
9种使用Chrome Firefox 自带调试工具调试javascript技巧
2017/12/22 Javascript
Layui tree 下拉菜单树的实例代码
2019/09/21 Javascript
微信小程序开发搜索功能实现(前端+后端+数据库)
2020/03/04 Javascript
vue如何搭建多页面多系统应用
2020/06/17 Javascript
浏览器JavaScript调试功能无法使用解决方案
2020/09/18 Javascript
[32:39]完美世界DOTA2联赛循环赛 Forest vs Inki BO2第一场 11.04
2020/11/04 DOTA
Python实现自动为照片添加日期并分类的方法
2017/09/30 Python
详解Python使用tensorflow入门指南
2018/02/09 Python
在python中获取div的文本内容并和想定结果进行对比详解
2019/01/02 Python
解决pycharm工程启动卡住没反应的问题
2019/01/19 Python
python numpy数组复制使用实例解析
2020/01/10 Python
Python实现进度条和时间预估的示例代码
2020/06/02 Python
城市轨道专业个人求职信范文
2013/09/23 职场文书
制冷与电控专业应届生求职信
2013/11/11 职场文书
咨询公司各岗位职责
2013/12/02 职场文书
就业自荐书
2013/12/05 职场文书
新年晚会主持词
2014/03/24 职场文书
珍惜资源保护环境的建议书
2014/05/14 职场文书
2014年绩效考核工作总结
2014/12/11 职场文书
2016优秀护士求职自荐信
2016/01/28 职场文书
Pygame Time时间控制的具体使用详解
2021/11/17 Python