内容表

  • platform — 访问底层平台的标识数据
    • 跨平台
    • Java 平台
    • Windows 平台
    • macOS 平台
    • Unix 平台
    • Linux 平台

上一话题

curses.panel — 用于 Curses 的面板堆栈扩展

下一话题
就业培训     下载中心     Wiki     联络
登录   注册

Log
  1. 首页
  2. Python 3.12.4
  3. 索引
  4. 模块
  5. 下一
  6. 上一
  7. Python 标准库
  8. 一般操作系统服务
  9. platform — 访问底层平台的标识数据

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 macOS (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 ( ) ¶

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

platform. node ( ) ¶

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

platform. platform ( aliased = False , terse = False ) ¶

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

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' 。返回空字符串若值无法确定。

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 .

processor is resolved late, on demand.

Note: the first two attribute names differ from the names presented by os.uname() , where they are named sysname and nodename .

Entries which cannot be determined are set to '' .

3.3 版改变: Result changed from a tuple to a namedtuple() .

3.9 版改变: processor is resolved late instead of immediately.

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). Values which cannot be determined are set to the defaults given as parameters (which all default to an empty string).

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, or None if the value cannot be determined. Possible values include but are not limited to 'Enterprise' , 'IoTUAP' , 'ServerStandard' ,和 'nanoserver' .

Added in version 3.8.

platform. win32_is_iot ( ) ¶

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

Added in version 3.8.

macOS 平台 ¶

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

Get macOS 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 字节。

Linux 平台 ¶

platform. freedesktop_os_release ( ) ¶

获取操作系统标识从 os-release 文件并以字典形式返回它。 os-release 文件是 freedesktop.org 标准 and is available in most Linux distributions. A noticeable exception is Android and Android-based distributions.

引发 OSError 或子类,当既不 /etc/os-release nor /usr/lib/os-release 可以被读取。

On success, the function returns a dictionary where keys and values are strings. Values have their special characters like " and $ unquoted. The fields NAME , ID ,和 PRETTY_NAME are always defined according to the standard. All other fields are optional. Vendors may include additional fields.

注意,字段像 NAME , VERSION ,和 VARIANT are strings suitable for presentation to users. Programs should use fields like ID , ID_LIKE , VERSION_ID ,或 VARIANT_ID to identify Linux distributions.

范例:

def get_like_distro():
    info = platform.freedesktop_os_release()
    ids = [info["ID"]]
    if "ID_LIKE" in info:
        # ids are space separated and ordered by precedence
        ids.extend(info["ID_LIKE"].split())
    return ids
												

Added in version 3.10.

内容表

  • platform — 访问底层平台的标识数据
    • 跨平台
    • Java 平台
    • Windows 平台
    • macOS 平台
    • Unix 平台
    • Linux 平台

上一话题

curses.panel — 用于 Curses 的面板堆栈扩展

下一话题

errno — 标准 errno 系统符号

本页

  • 报告 Bug
  • 展示源

快速搜索

键入搜索术语或模块、类、函数名称。

  1. 首页
  2. Python 3.12.4
  3. 索引
  4. 模块
  5. 下一
  6. 上一
  7. Python 标准库
  8. 一般操作系统服务
  9. platform — 访问底层平台的标识数据
  10. 版权所有  © 2014-2026 乐数软件    

    工业和信息化部: 粤ICP备14079481号-1