Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a83cdaa

Browse files
committed
Issue #12326: document the recommended idiom for checking sys.platform on Unix systems.
Also, point to the various alternatives.
1 parent 00ebeb5 commit a83cdaa

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

Doc/library/os.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ Notes on the availability of these functions:
6161
names have currently been registered: ``'posix'``, ``'nt'``, ``'mac'``,
6262
``'os2'``, ``'ce'``, ``'java'``.
6363

64+
.. seealso::
65+
:attr:`sys.platform` has a finer granularity. :func:`os.uname` gives
66+
system-dependent version information.
67+
68+
The :mod:`platform` module provides detailed checks for the
69+
system's identity.
70+
6471

6572
.. _os-filenames:
6673

Doc/library/sys.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,12 @@ always available.
714714
For Unix systems, this is the lowercased OS name as returned by ``uname -s``
715715
with the first part of the version as returned by ``uname -r`` appended,
716716
e.g. ``'sunos5'`` or ``'linux2'``, *at the time when Python was built*.
717+
Unless you want to test for a specific system version, it is therefore
718+
recommended to use the following idiom::
719+
720+
if sys.platform.startswith('linux'):
721+
# Linux-specific code here...
722+
717723
For other systems, the values are:
718724

719725
================ ===========================
@@ -726,6 +732,12 @@ always available.
726732
OS/2 EMX ``'os2emx'``
727733
================ ===========================
728734

735+
.. seealso::
736+
:attr:`os.name` has a coarser granularity. :func:`os.uname` gives
737+
system-dependent version information.
738+
739+
The :mod:`platform` module provides detailed checks for the
740+
system's identity.
729741

730742
.. data:: prefix
731743

0 commit comments

Comments
 (0)