platform — 访问底层平台的标识数据

源代码: Lib/platform.py


注意

具体平台按字母顺序列出,Unix 部分包含 Linux。

跨平台

platform. architecture ( executable=sys.executable , bits='' , linkage='' )

查询给定可执行文件 (默认为 Python 解释器二进制文件) 为各种体系结构信息。

返回元组 (bits, linkage) 其中包含可执行文件使用的位体系结构和链接格式的有关信息。两者值以字符串形式返回。

无法确定的值按预置参数给定方式返回。若 bits 给定为 '' sizeof(pointer) (或 sizeof(long) on Python version < 1.5.2) is used as indicator for the supported pointer size.

函数依赖系统 file command to do the actual work. This is available on most if not all Unix platforms and some non-Unix platforms and then only if the executable points to the Python interpreter. Reasonable defaults are used when the above needs are not met.

注意

On Mac OS X (and perhaps other platforms), executable files may be universal files containing multiple architectures.

To get at the “64-bitness” of the current interpreter, it is more reliable to query the sys.maxsize 属性:

is_64bits = sys.maxsize > 2**32
						
platform. machine ( )

返回机器类型,如 'i386' 。返回空字符串若值无法确定。

platform. node ( )

返回计算机的网络名称 (可能并非完全合格)。返回空字符串若值无法确定。

platform. platform ( aliased=0 , terse=0 )

返回标识底层平台,带有尽可能多有用信息的单字符串。

The output is intended to be human readable rather than machine parseable. It may look different on different platforms and this is intended.

aliased is true, the function will use aliases for various platforms that report system names which differ from their common names, for example SunOS will be reported as Solaris. The system_alias() function is used to implement this.

设置 terse to true causes the function to return only the absolute minimum information needed to identify the platform.

3.8 版改变: 在 macOS,函数现在使用 mac_ver() , if it returns a non-empty release string, to get the macOS version rather than the darwin version.

platform. processor ( )

返回 (真实) 处理器名称,如 'amdk6' .

An empty string is returned if the value cannot be determined. Note that many platforms do not provide this information or simply return the same value as for machine() . NetBSD does this.

platform. python_build ( )

返回元组 (buildno, builddate) 以字符串形式声明 Python 构建编号和日期。

platform. python_compiler ( )

返回用于编译 Python 的编译器标识字符串。

platform. python_branch ( )

返回 Python 实现 SCM 分支的标识字符串。

platform. python_implementation ( )

返回 Python 实现标识字符串。可能的返回值,包括:CPython、IronPython、Jython、PyPy。

platform. python_revision ( )

返回 Python 实现 SCM 修订标识字符串。

platform. python_version ( )

返回 Python 版本如字符串 'major.minor.patchlevel' .

注意,不像 Python sys.version ,返回值将始终包括补丁级别 (默认为 0)。

platform. python_version_tuple ( )

返回 Python 版本如元组 (major, minor, patchlevel) 按字符串。

注意,不像 Python sys.version , the returned value will always include the patchlevel (it defaults to '0' ).

platform. release ( )

返回系统的发行,如 '2.2.0' or 'NT' An empty string is returned if the value cannot be determined.

platform. system ( )

返回系统/OS 名称,譬如 'Linux' , 'Darwin' , 'Java' , 'Windows' 。返回空字符串若值无法确定。

platform. system_alias ( system , release , version )

返回 (system, release, version) aliased to common marketing names used for some systems. It also does some reordering of the information in some cases where it would otherwise cause confusion.

platform. version ( )

返回系统的发行版本,如 '#3 on degas' 。返回空字符串若值无法确定。

platform. uname ( )

相当可移植的 uname 接口。返回 namedtuple() 包含 6 属性: system , node , release , version , machine ,和 processor .

注意,这添加的第 6 属性 ( processor ) 不会呈现在 os.uname() result. Also, the attribute names are different for the first two attributes; os.uname() names them sysname and nodename .

Entries which cannot be determined are set to '' .

3.3 版改变: 将结果从元组更改为命名元组。

Java 平台

platform. java_ver ( release='' , vendor='' , vminfo=('' , '' , '') , osinfo=('' , '' , '') )

用于 Jython 的版本接口。

返回元组 (release, vendor, vminfo, osinfo) with vminfo 是元组 (vm_name, vm_release, vm_vendor) and osinfo 是元组 (os_name, os_version, os_arch) . Values which cannot be determined are set to the defaults given as parameters (which all default to '' ).

Windows 平台

platform. win32_ver ( release='' , version='' , csd='' , ptype='' )

Get additional version information from the Windows Registry and return a tuple (release, version, csd, ptype) referring to OS release, version number, CSD level (service pack) and OS type (multi/single processor).

As a hint: ptype is 'Uniprocessor Free' on single processor NT machines and 'Multiprocessor Free' on multi processor machines. The ‘Free’ refers to the OS version being free of debugging code. It could also state ‘Checked’ which means the OS version uses debugging code, i.e. code that checks arguments, ranges, etc.

platform. win32_edition ( )

Returns a string representing the current Windows edition. Possible values include but are not limited to 'Enterprise' , 'IoTUAP' , 'ServerStandard' ,和 'nanoserver' .

3.8 版新增。

platform. win32_is_iot ( )

返回 True 若 Windows 版本返回通过 win32_edition() 被识别成 IoT (物联网) 版。

3.8 版新增。

Mac OS 平台

platform. mac_ver ( release='' , versioninfo=('' , '' , '') , machine='' )

Get Mac OS version information and return it as tuple (release, versioninfo, machine) with versioninfo 是元组 (version, dev_stage, non_release_version) .

Entries which cannot be determined are set to '' . All tuple entries are strings.

Unix 平台

platform. libc_ver ( executable=sys.executable , lib='' , version='' , chunksize=16384 )

Tries to determine the libc version against which the file executable (defaults to the Python interpreter) is linked. Returns a tuple of strings (lib, version) which default to the given parameters in case the lookup fails.

Note that this function has intimate knowledge of how different libc versions add symbols to the executable is probably only usable for executables compiled using gcc .

The file is read and scanned in chunks of chunksize 字节。