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之再深点,更懂list
Sep 20 Python
python调用机器喇叭发出蜂鸣声(Beep)的方法
Mar 23 Python
python实现pdf转换成word/txt纯文本文件
Jun 07 Python
Python实现读取SQLServer数据并插入到MongoDB数据库的方法示例
Jun 09 Python
Python编程中flask的简介与简单使用
Dec 28 Python
python文件选择对话框的操作方法
Jun 27 Python
Python批量修改图片分辨率的实例代码
Jul 04 Python
python flask web服务实现更换默认端口和IP的方法
Jul 26 Python
Python高阶函数、常用内置函数用法实例分析
Dec 26 Python
Python 安装 virturalenv 虚拟环境的教程详解
Feb 21 Python
在python image 中实现安装中文字体
May 16 Python
python opencv pytesseract 验证码识别的实现
Aug 28 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
Symfony2安装第三方Bundles实例详解
2016/02/04 PHP
laravel 实现划分admin和home 模块分组
2019/10/15 PHP
Prototype PeriodicalExecuter对象 学习
2009/07/19 Javascript
再次分享18个非常棒的jQuery表格插件
2011/04/10 Javascript
关闭浏览器输入框自动补齐 兼容IE,FF,Chrome等主流浏览器
2014/02/11 Javascript
让JavaScript和其它资源并发下载的方法
2014/10/16 Javascript
jquery+ajax验证不通过也提交表单问题处理
2014/12/12 Javascript
JQuery遍历DOM节点的方法
2015/06/11 Javascript
js实现防止被iframe的方法
2015/07/03 Javascript
JS+CSS实现另类带提示效果的竖向导航菜单
2015/10/15 Javascript
10个JavaScript中易犯小错误
2016/02/14 Javascript
JavaScript代码实现左右上下自动晃动自动移动
2016/04/08 Javascript
React.js入门实例教程之创建hello world 的5种方式
2016/05/11 Javascript
jQuery过滤选择器用法示例
2016/09/12 Javascript
React通过父组件传递类名给子组件的实现方法
2017/11/13 Javascript
详解Vue-axios 设置请求头问题
2018/12/06 Javascript
layui实现tab的添加拒绝重复的方法
2019/09/04 Javascript
mpvue网易云短信接口实现小程序短信登录的示例代码
2020/04/03 Javascript
vue webpack build资源相对路径的问题及解决方法
2020/06/04 Javascript
Python正则表达式常用函数总结
2017/06/24 Python
PyQt5 QTable插入图片并动态更新的实例
2019/06/18 Python
Pandas中resample方法详解
2019/07/02 Python
解决paramiko执行命令超时的问题
2020/04/16 Python
python函数调用,循环,列表复制实例
2020/05/03 Python
运行python提示no module named sklearn的解决方法
2020/11/29 Python
HTML5本地存储之Web Storage应用介绍
2013/01/06 HTML / CSS
国际鲜花速递专家:Floraqueen
2016/11/24 全球购物
英国Office鞋店德国网站:在线购买鞋子、靴子和运动鞋
2018/12/19 全球购物
世界排名第一的运动鞋市场:Flight Club
2020/01/03 全球购物
Orlebar Brown官网:设计师泳裤和泳装
2020/12/08 全球购物
销售助理岗位职责
2015/02/11 职场文书
大学考试作弊检讨书
2015/05/06 职场文书
2015年青年志愿者工作总结
2015/05/20 职场文书
小人国观后感
2015/06/11 职场文书
2015年小学远程教育工作总结
2015/07/28 职场文书
深度学习tensorflow基础mnist
2021/04/14 Python