Skip to content

Commit

Permalink
Update sys.platform documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsmith committed Mar 5, 2024
1 parent 1a97f87 commit 4431efc
Showing 1 changed file with 20 additions and 25 deletions.
45 changes: 20 additions & 25 deletions Doc/library/sys.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1367,47 +1367,42 @@ always available.

.. data:: platform

This string contains a platform identifier that can be used to append
platform-specific components to :data:`sys.path`, for instance.

For Unix systems, except on Linux and AIX, this is the lowercased OS name as
returned by ``uname -s`` with the first part of the version as returned by
``uname -r`` appended, e.g. ``'sunos5'`` or ``'freebsd8'``, *at the time
when Python was built*. Unless you want to test for a specific system
version, it is therefore recommended to use the following idiom::

if sys.platform.startswith('freebsd'):
# FreeBSD-specific code here...
elif sys.platform.startswith('linux'):
# Linux-specific code here...
elif sys.platform.startswith('aix'):
# AIX-specific code here...

For other systems, the values are:
A string containing a platform identifier. Known values are:

================ ===========================
System ``platform`` value
================ ===========================
Android ``'android'``
AIX ``'aix'``
Emscripten ``'emscripten'``
iOS ``'ios'``
Linux ``'linux'``
WASI ``'wasi'``
macOS ``'darwin'``
Windows ``'win32'``
Windows/Cygwin ``'cygwin'``
macOS ``'darwin'``
WASI ``'wasi'``
================ ===========================

On Unix systems not listed in the table, the value is the lowercased OS name
as returned by ``uname -s``, with the first part of the version as returned by
``uname -r`` appended, e.g. ``'sunos5'`` or ``'freebsd8'``, *at the time
when Python was built*. Unless you want to test for a specific system
version, it is therefore recommended to use the following idiom::

if sys.platform.startswith('freebsd'):
# FreeBSD-specific code here...

.. versionchanged:: 3.3
On Linux, :data:`sys.platform` doesn't contain the major version anymore.
It is always ``'linux'``, instead of ``'linux2'`` or ``'linux3'``. Since
older Python versions include the version number, it is recommended to
always use the ``startswith`` idiom presented above.
It is always ``'linux'``, instead of ``'linux2'`` or ``'linux3'``.

.. versionchanged:: 3.8
On AIX, :data:`sys.platform` doesn't contain the major version anymore.
It is always ``'aix'``, instead of ``'aix5'`` or ``'aix7'``. Since
older Python versions include the version number, it is recommended to
always use the ``startswith`` idiom presented above.
It is always ``'aix'``, instead of ``'aix5'`` or ``'aix7'``.

.. versionchanged:: 3.13
On Android, :data:`sys.platform` now returns ``'android'``` rather than
``'linux'``.

.. seealso::

Expand Down

0 comments on commit 4431efc

Please sign in to comment.