在 Python 中访问底层平台的标识数据
pythonserver side programmingprogramming
platform 模块中的函数可帮助我们探测底层平台的硬件、操作系统和解释器版本信息。
architecture()
此函数查询给定的可执行文件(默认为 Python 解释器可执行文件)以获取各种体系结构信息。
>>> import platform >>> platform.architecture() ('64bit', '')
machine()
此函数返回机器类型,例如 'i386'。如果无法确定值,则返回空字符串。
>>> platform.machine() 'x86_64'
node()
此函数返回计算机的网络名称。
>>> platform.node() 'malhar-ubuntu'
platform(aliased=0, terse=0)
此函数返回一个字符串,用于标识底层平台。
>>> platform.platform() 'Linux-4.13.0-46-generic-x86_64-with-debian-stretch-sid'
processor()
此函数返回(真实)处理器名称。
>>> platform.processor() 'x86_64'
python_build()
此函数返回一个元组 (buildno, builddate)
>>> platform.python_build() ('default', 'Oct 13 2017 12:02:49')
python_compiler()
此函数返回一个字符串,用于标识用于编译 Python 的编译器。
>>> platform.python_compiler() 'GCC 7.2.0'
python_implementation()
此函数返回一个字符串,用于标识 Python 实现。可能的返回值为:‘CPython’、‘IronPython’、‘Jython’、‘PyPy’。
>>> platform.python_implementation() 'CPython'
python_version()
此函数返回一个字符串,其中包含 Python 版本,格式为 'major.minor.patchlevel'。
>>> platform.python_version() '3.6.3'
System()
此函数返回系统/操作系统名称
>>> platform.system() 'Linux'
uname()
相当可移植的 uname 接口。返回包含六个属性的 namedtuple():系统、节点、发布、版本、机器和处理器。
>>> platform.uname() uname_result(system='Linux', node='malhar-ubuntu', release='4.13.0-46-generic', version='#51-Ubuntu SMP Tue Jun 12 12:36:29 UTC 2018', machine='x86_64', processor='x86_64')