根据官方文档的解释(https://docs.python.org/3.5/library/platform.html#module-platform):

学习其他人的代码如下:

# python platform

# Author   :   Hongten
# Mailto : hongtenzone@foxmail.com
# Blog : http://www.cnblogs.com/hongten
# QQ : 648719819
# Version : 1.0
# Create : 2013-08-28 import platform '''
python中,platform模块给我们提供了很多方法去获取操作系统的信息
如:
import platform
platform.platform() #获取操作系统名称及版本号,'Windows-7-6.1.7601-SP1'
platform.version() #获取操作系统版本号,'6.1.7601'
platform.architecture() #获取操作系统的位数,('32bit', 'WindowsPE')
platform.machine() #计算机类型,'x86'
platform.node() #计算机的网络名称,'hongjie-PC'
platform.processor() #计算机处理器信息,'x86 Family 16 Model 6 Stepping 3, AuthenticAMD'
platform.uname() #包含上面所有的信息汇总,uname_result(system='Windows', node='hongjie-PC',
release='7', version='6.1.7601', machine='x86', processor='x86 Family
16 Model 6 Stepping 3, AuthenticAMD') 还可以获得计算机中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_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 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 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每日一类(2):platform的更多相关文章

  1. python每日一类(3):os和sys

    os与sys模块的官方解释如下: os: This module provides a portable way of using operating system dependent functio ...

  2. python每日一类(4):slice

    class slice(stop)class slice(start, stop[, step]) Return a slice object representing the set of indi ...

  3. python每日一类(1):pathlib

    每天学习一个python的类(大多数都是第三方的),聚沙成金. -------------------------------------------------------------------- ...

  4. python每日一类(5):itertools模块

    itertools模块包含创建有效迭代器的函数,可以用各种方式对数据进行循环操作,此模块中的所有函数返回的迭代器都可以与for循环语句以及其他包含迭代器(如生成器和生成器表达式)的函数联合使用. ch ...

  5. Python每日一练(1):计算文件夹内各个文章中出现次数最多的单词

    #coding:utf-8 import os,re path = 'test' files = os.listdir(path) def count_word(words): dic = {} ma ...

  6. Python之路--你不知道的platform

    某次在查看测试机(Ubuntu)发行版本时,发现得到的结果并不准确:本应得到Ubuntu,结果显示的却是Debian,大致代码如下 ... distribution_name = ['centos', ...

  7. python每日一函数 - divmod数字处理函数

    python每日一函数 - divmod数字处理函数 divmod(a,b)函数 中文说明: divmod(a,b)方法返回的是a//b(除法取整)以及a对b的余数 返回结果类型为tuple 参数: ...

  8. python每日一练:0007题

    第 0007 题: 有个目录,里面是你自己写过的程序,统计一下你写过多少行代码.包括空行和注释,但是要分别列出来. # -*- coding:utf-8 -*- import os def count ...

  9. [python每日一练]--0012:敏感词过滤 type2

    题目链接:https://github.com/Show-Me-the-Code/show-me-the-code代码github链接:https://github.com/wjsaya/python ...

随机推荐

  1. Redis数据更新

    技术交流群: 233513714

  2. Field 'flag' doesn't have a default value错误

    错误代码: java.sql.SQLException: Field 'flag' doesn't have a default value at com.mysql.jdbc.SQLError.cr ...

  3. Eclipse 透视图(Perspective)---Eclipse教程第06课

    什么是透视图? 透视图是一个包含一系列视图和内容编辑器的可视容器.默认的透视图叫 java. Eclipse 窗口可以打开多个透视图,但在同一时间只能有一个透视图处于激活状态. 用户可以在两个透视图之 ...

  4. 【Balanced Binary Tree】cpp

    题目: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced bin ...

  5. jmeter之录制控制器与代理的使用

    1.       先启动jmeter,在测试计划中添加线程组 2.       选中线程组右键添加,在配置元件中点击HTTP请求默认值 3.       选中线程组右键添加,在逻辑控制器中点击录制控制 ...

  6. shell之进程

    ps     System V 风格  -         -elF         -ef         -eF     BSD            a所有跟终端有关的进程           ...

  7. JavaScript之实现单选复选、菜单以及返回顶部实例

    1.单选.复选以及反选实例 其实主要是利用for循环提取标签,然后更改checked属性值实现的 <!DOCTYPE html> <html lang="en"& ...

  8. 团队Alpha版本冲刺(四)

    目录 组员情况 组员1(组长):胡绪佩 组员2:胡青元 组员3:庄卉 组员4:家灿 组员5:凯琳 组员6:丹丹 组员7:何家伟 组员8:政演 组员9:鸿杰 组员10:刘一好 组员:何宇恒 展示组内最新 ...

  9. JDK从1.8升级到9.0.1后sun.misc.BASE64Decoder和sun.misc.BASE64Encoder不可用

    目录 描述 原因分析 处理办法 参考 描述 最近研究把项目的JDK升级从1.8升级到9.0.1,在eclipse上配置好JDK为9后,发现项目有错,查看发现sun.misc.BASE64Decoder ...

  10. Scala 基础(2)—— 基本数据结构

    1. Scala 的面向对象 在学习 Java 的时候,我们说 Java 是一门面向对象的语言,然而 Java 其实并没有完全遵守“一切皆对象”这一准则. 例如:Java 的8种基本数据类型 & ...