platform 模块主要功能是,提供平台的一些信息,包括操作系统信息,python版本信息等。不同的平台获取的信息不同。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# 平台信息,体系结构信息
print("platform.platform() -> ", platform.platform())
print("platform.architecture() -> ", platform.architecture())
print("platform.mac_ver() -> ", platform.mac_ver())
print("platform.win32_ver() -> ", platform.win32_ver())
print("platform.machine() -> ", platform.machine())
print("platform.processor() -> ", platform.processor())

platform.platform() ->  Linux-4.15.0-44-generic-x86_64-with-Ubuntu-18.04-bionic
platform.architecture() ->  ('64bit', 'ELF')
platform.mac_ver() ->  ('', ('', '', ''), '')
platform.win32_ver() ->  ('', '', '', '')
platform.machine() ->  x86_64
platform.processor() ->  x86_64
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# uname()包含下面所有函数的信息
print("\nplatform.uname() -> ", platform.uname())
print("platform.system() -> ", platform.system())
print("platform.node() -> ", platform.node())
print("platform.release() -> ", platform.release())
print("platform.version() -> ", platform.version())
print("platform.machine() -> ", platform.machine())
print("platform.processor() -> ", platform.processor())

platform.uname() ->  uname_result(system='Linux', node='ubuntu', release='4.15.0-44-generic', version='#47-Ubuntu SMP Mon Jan 14 11:26:59 UTC 2019', machine='x86_64', processor='x86_64')
platform.system() ->  Linux
platform.node() ->  ubuntu
platform.release() ->  4.15.0-44-generic
platform.version() ->  #47-Ubuntu SMP Mon Jan 14 11:26:59 UTC 2019
platform.machine() ->  x86_64
platform.processor() ->  x86_64
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# linux信息
print("\nplatform.libc_ver() -> ", platform.libc_ver())
print("platform.linux_distribution() -> ", platform.linux_distribution())
print("platform.dist() -> ", platform.dist())
print("platform.popen(\"ls - l\").read() -> ", platform.popen("ls -l").read())

platform.libc_ver() ->  ('glibc', '2.25')
platform.linux_distribution() ->  ('Ubuntu', '18.04', 'bionic')
platform.dist() ->  ('Ubuntu', '18.04', 'bionic')
platform.popen("ls - l").read() ->  总用量 8
-rw-rw-r-- 1 xiaohui xiaohui  164 1  23 16:49 11.1 platform.md
-rw-rw-r-- 1 xiaohui xiaohui 1698 1  23 16:44 11.1 platform.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# python相关信息,值得注意的是,java_ver()指的是Jython的信息
print("\nplatform.python_version() -> ", platform.python_version())
print("platform.python_version_tuple() -> ", platform.python_version_tuple())
print("platform.python_branch() -> ", platform.python_branch())
print("platform.python_build() -> ", platform.python_build())
print("platform.python_compiler() -> ", platform.python_compiler())
print("platform.python_implementation() -> ", platform.python_implementation())
print("platform.python_revision() -> ", platform.python_revision())

platform.python_version() ->  3.6.7
platform.python_version_tuple() ->  ('3', '6', '7')
platform.python_branch() ->  
platform.python_build() ->  ('default', 'Oct 22 2018 11:32:17')
platform.python_compiler() ->  GCC 8.2.0
platform.python_implementation() ->  CPython
platform.python_revision() ->