Skip to content

Commit d49bd1a

Browse files
committed
Update sys.platform documentation
1 parent 1a97f87 commit d49bd1a

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

Doc/library/sys.rst

+20-25
Original file line numberDiff line numberDiff line change
@@ -1367,47 +1367,42 @@ always available.
13671367

13681368
.. data:: platform
13691369

1370-
This string contains a platform identifier that can be used to append
1371-
platform-specific components to :data:`sys.path`, for instance.
1372-
1373-
For Unix systems, except on Linux and AIX, this is the lowercased OS name as
1374-
returned by ``uname -s`` with the first part of the version as returned by
1375-
``uname -r`` appended, e.g. ``'sunos5'`` or ``'freebsd8'``, *at the time
1376-
when Python was built*. Unless you want to test for a specific system
1377-
version, it is therefore recommended to use the following idiom::
1378-
1379-
if sys.platform.startswith('freebsd'):
1380-
# FreeBSD-specific code here...
1381-
elif sys.platform.startswith('linux'):
1382-
# Linux-specific code here...
1383-
elif sys.platform.startswith('aix'):
1384-
# AIX-specific code here...
1385-
1386-
For other systems, the values are:
1370+
A string containing a platform identifier. Known values are:
13871371

13881372
================ ===========================
13891373
System ``platform`` value
13901374
================ ===========================
13911375
AIX ``'aix'``
1376+
Android ``'android'``
13921377
Emscripten ``'emscripten'``
1378+
iOS ``'ios'``
13931379
Linux ``'linux'``
1394-
WASI ``'wasi'``
1380+
macOS ``'darwin'``
13951381
Windows ``'win32'``
13961382
Windows/Cygwin ``'cygwin'``
1397-
macOS ``'darwin'``
1383+
WASI ``'wasi'``
13981384
================ ===========================
13991385

1386+
On Unix systems not listed in the table, the value is the lowercased OS name
1387+
as returned by ``uname -s``, with the first part of the version as returned by
1388+
``uname -r`` appended, e.g. ``'sunos5'`` or ``'freebsd8'``, *at the time
1389+
when Python was built*. Unless you want to test for a specific system
1390+
version, it is therefore recommended to use the following idiom::
1391+
1392+
if sys.platform.startswith('freebsd'):
1393+
# FreeBSD-specific code here...
1394+
14001395
.. versionchanged:: 3.3
14011396
On Linux, :data:`sys.platform` doesn't contain the major version anymore.
1402-
It is always ``'linux'``, instead of ``'linux2'`` or ``'linux3'``. Since
1403-
older Python versions include the version number, it is recommended to
1404-
always use the ``startswith`` idiom presented above.
1397+
It is always ``'linux'``, instead of ``'linux2'`` or ``'linux3'``.
14051398

14061399
.. versionchanged:: 3.8
14071400
On AIX, :data:`sys.platform` doesn't contain the major version anymore.
1408-
It is always ``'aix'``, instead of ``'aix5'`` or ``'aix7'``. Since
1409-
older Python versions include the version number, it is recommended to
1410-
always use the ``startswith`` idiom presented above.
1401+
It is always ``'aix'``, instead of ``'aix5'`` or ``'aix7'``.
1402+
1403+
.. versionchanged:: 3.13
1404+
On Android, :data:`sys.platform` now returns ``'android'`` rather than
1405+
``'linux'``.
14111406

14121407
.. seealso::
14131408

0 commit comments

Comments
 (0)