mirror of
https://github.com/python/cpython.git
synced 2025-11-12 07:02:33 +00:00
Update sys.platform doc for #12326.
This commit is contained in:
parent
987b188615
commit
a47e53e42e
1 changed files with 25 additions and 15 deletions
|
|
@ -699,26 +699,36 @@ always available.
|
||||||
This string contains a platform identifier that can be used to append
|
This string contains a platform identifier that can be used to append
|
||||||
platform-specific components to :data:`sys.path`, for instance.
|
platform-specific components to :data:`sys.path`, for instance.
|
||||||
|
|
||||||
For Unix systems, this is the lowercased OS name as returned by ``uname -s``
|
For most Unix systems, this is the lowercased OS name as returned by ``uname
|
||||||
with the first part of the version as returned by ``uname -r`` appended,
|
-s`` with the first part of the version as returned by ``uname -r`` appended,
|
||||||
e.g. ``'sunos5'`` or ``'linux2'``, *at the time when Python was built*.
|
e.g. ``'sunos5'``, *at the time when Python was built*. Unless you want to
|
||||||
Unless you want to test for a specific system version, it is therefore
|
test for a specific system version, it is therefore recommended to use the
|
||||||
recommended to use the following idiom::
|
following idiom::
|
||||||
|
|
||||||
if sys.platform.startswith('linux'):
|
if sys.platform.startswith('freebsd'):
|
||||||
|
# FreeBSD-specific code here...
|
||||||
|
elif sys.platform.startswith('linux'):
|
||||||
# Linux-specific code here...
|
# Linux-specific code here...
|
||||||
|
|
||||||
|
.. versionchanged:: 3.2.2
|
||||||
|
Since lots of code check for ``sys.platform == 'linux2'``, and there is
|
||||||
|
no essential change between Linux 2.x and 3.x, ``sys.platform`` is always
|
||||||
|
set to ``'linux2'``, even on Linux 3.x. In Python 3.3 and later, the
|
||||||
|
value will always be set to ``'linux'``, so it is recommended to always
|
||||||
|
use the ``startswith`` idiom presented above.
|
||||||
|
|
||||||
For other systems, the values are:
|
For other systems, the values are:
|
||||||
|
|
||||||
================ ===========================
|
====================== ===========================
|
||||||
System :data:`platform` value
|
System :data:`platform` value
|
||||||
================ ===========================
|
====================== ===========================
|
||||||
Windows ``'win32'``
|
Linux (2.x *and* 3.x) ``'linux2'``
|
||||||
Windows/Cygwin ``'cygwin'``
|
Windows ``'win32'``
|
||||||
Mac OS X ``'darwin'``
|
Windows/Cygwin ``'cygwin'``
|
||||||
OS/2 ``'os2'``
|
Mac OS X ``'darwin'``
|
||||||
OS/2 EMX ``'os2emx'``
|
OS/2 ``'os2'``
|
||||||
================ ===========================
|
OS/2 EMX ``'os2emx'``
|
||||||
|
====================== ===========================
|
||||||
|
|
||||||
.. seealso::
|
.. seealso::
|
||||||
:attr:`os.name` has a coarser granularity. :func:`os.uname` gives
|
:attr:`os.name` has a coarser granularity. :func:`os.uname` gives
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue