platform可用于查询底层平台的标识数据,下表为其中封装的无参数函数
| 函数 | 返回值 |
|---|---|
system | 操作系统名称 |
node | 计算机名称 |
release | 操作系统的主版本 |
version | 操作系统的发布版本 |
machine | 返回机器类型 |
processor | 处理器名称 |
uname | 返回前面的六项 |
python_build | python编译代码和日期 |
python_compiler | Python编译器标志 |
python_branch | SCM 分支 |
python_revision | SCM 修订版 |
python_implementation | 编写Python的语言 |
python_version | Python版本 |
python_version_tuple | Python版本的元组 |
下面对部分函数做下测试
>>> import platform
>>> platform.node()
'Laser'
>>> platform.processor()
'Intel64 Family 6 Model 158 Stepping 10, GenuineIntel'
>>> platform.python_build()
('main', 'Aug 25 2022 23:51:50')
>>> platform.python_compiler()
'MSC v.1916 64 bit (AMD64)'
>>> platform.python_branch()
''
>>> platform.python_implementation()
'CPython'
>>> platform.python_revision()
''
>>> platform.python_version()
'3.9.13'
>>> platform.python_version_tuple()
('3', '9', '13')
>>> platform.release()
'10'
>>> platform.version()
'10.0.22621'
>>> platform.machine()
'AMD64'
>>> platform.uname()
uname_result(system='Windows', node='Laser', release='10', version='10.0.22621', machine='AMD64')
platform模块中,除了这些无参数的函数之外,还有几个相对复杂的函数。
architecture用于查询给定的可执行文件,定义如下
architecture(executable=sys.executable, bits='', linkage='')
其中,executable为可执行文件,为一个路径,默认为sys.excutable,也就是Python的绝对路径。bits为程序位数,32位或者64位,''将自行判断;linkage为链接格式。
>>> platform.architecture()
('64bit', 'WindowsPE')
platform.platform(aliased=0, terse=0)可返回一个标识底层平台的字符串,包含尽可能多的有用信息。其两个参数均为布尔型
aliased为True,将使用各种平台不同与其通常名称的别名来报告系统名称,例如 SunOS 将被报告为 Solaris。terse为True,则只返回标识平台所必须的最小量信息。platform.system_alias是一个意义不明的函数,使用方法如下,据标准库所说,可以返回常用的营销名称。
>>> platform.system()
'Windows'
>>> platform.release()
'10'
>>> platform.version()
'10.0.22621'
>>> platform.system_alias(platform.system(), platform.release(), platform.version())
('Windows', '10', '10.0.22621')