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进阶教程之词典、字典、dict
Aug 29 Python
详解Python中的各种函数的使用
May 24 Python
Python的Flask框架的简介和安装方法
Nov 13 Python
Python中的左斜杠、右斜杠(正斜杠和反斜杠)
Aug 30 Python
打包发布Python模块的方法详解
Sep 18 Python
python实现泊松图像融合
Jul 26 Python
Python中低维数组填充高维数组的实现
Dec 02 Python
浅谈在JupyterNotebook下导入自己的模块的问题
Apr 16 Python
Python requests上传文件实现步骤
Sep 15 Python
matplotlib教程——强大的python作图工具库
Oct 15 Python
Python调用JavaScript代码的方法
Oct 27 Python
Python requests用法和django后台处理详解
Mar 19 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程序员工具
2008/05/26 PHP
PHPWind 发帖回帖Api PHP版打包下载
2010/02/08 PHP
php根据身份证号码计算年龄的实例代码
2014/01/18 PHP
PHP网络操作函数汇总
2015/05/18 PHP
php实现点击可刷新验证码
2015/11/07 PHP
js操作二级联动实现代码
2010/07/27 Javascript
在父页面得到zTree已选中的节点的方法
2015/02/12 Javascript
flash+jQuery实现可关闭及重复播放的压顶广告
2015/04/15 Javascript
js表单中选择框值的获取及表单的序列化
2015/12/17 Javascript
Angularjs中使用Filters详解
2016/03/11 Javascript
jquery计算出left和top,让一个div水平垂直居中的简单实例
2016/07/13 Javascript
AngularJS中$watch和$timeout的使用示例
2016/09/20 Javascript
简单实现jQuery多选框功能
2017/01/09 Javascript
jsonp跨域及实现百度首页联想功能的方法
2018/08/30 Javascript
angular2组件中定时刷新并清除定时器的实例讲解
2018/08/31 Javascript
Vue递归组件+Vuex开发树形组件Tree--递归组件的简单实现
2019/04/01 Javascript
小程序实现层叠卡片滑动效果
2019/08/26 Javascript
创建与框架无关的JavaScript插件
2020/12/01 Javascript
实用的 vue tags 创建缓存导航的过程实现
2020/12/03 Vue.js
Python中利用sqrt()方法进行平方根计算的教程
2015/05/15 Python
解决nohup重定向python输出到文件不成功的问题
2018/05/11 Python
Python global全局变量函数详解
2018/09/18 Python
啥是佩奇?使用Python自动绘画小猪佩奇的代码实例
2019/02/20 Python
Django Admin中增加导出CSV功能过程解析
2019/09/04 Python
html5移动端价格输入键盘的实现
2019/09/16 HTML / CSS
竞职演讲稿范文
2014/01/11 职场文书
自荐书范文范例
2014/02/13 职场文书
政府个人对照检查材料思想汇报
2014/10/08 职场文书
工作经历证明书范文
2014/11/02 职场文书
优秀护士事迹材料
2014/12/25 职场文书
2015年六一儿童节活动方案
2015/05/05 职场文书
政审证明材料
2015/06/19 职场文书
创业计划书之韩国烧烤店
2019/09/19 职场文书
MyBatis-Plus 批量插入数据的操作方法
2021/09/25 Java/Android
pycharm安装深度学习pytorch的d2l包失败问题解决
2022/03/25 Python
Python使用Beautiful Soup(BS4)库解析HTML和XML
2022/06/05 Python