699
699
This string contains a platform identifier that can be used to append
700
700
platform-specific components to :data:`sys.path`, for instance.
702
For Unix systems, this is the lowercased OS name as returned by ``uname -s``
703
with the first part of the version as returned by ``uname -r`` appended,
704
e.g. ``'sunos5'`` or ``'linux2'``, *at the time when Python was built*.
705
Unless you want to test for a specific system version, it is therefore
706
recommended to use the following idiom::
702
For most Unix systems, this is the lowercased OS name as returned by ``uname
703
-s`` with the first part of the version as returned by ``uname -r`` appended,
704
e.g. ``'sunos5'``, *at the time when Python was built*. Unless you want to
705
test for a specific system version, it is therefore recommended to use the
708
if sys.platform.startswith('linux'):
708
if sys.platform.startswith('freebsd'):
709
# FreeBSD-specific code here...
710
elif sys.platform.startswith('linux'):
709
711
# Linux-specific code here...
713
.. versionchanged:: 3.2.2
714
Since lots of code check for ``sys.platform == 'linux2'``, and there is
715
no essential change between Linux 2.x and 3.x, ``sys.platform`` is always
716
set to ``'linux2'``, even on Linux 3.x. In Python 3.3 and later, the
717
value will always be set to ``'linux'``, so it is recommended to always
718
use the ``startswith`` idiom presented above.
711
720
For other systems, the values are:
713
================ ===========================
714
System :data:`platform` value
715
================ ===========================
717
Windows/Cygwin ``'cygwin'``
718
Mac OS X ``'darwin'``
720
OS/2 EMX ``'os2emx'``
721
================ ===========================
722
====================== ===========================
723
System :data:`platform` value
724
====================== ===========================
725
Linux (2.x *and* 3.x) ``'linux2'``
727
Windows/Cygwin ``'cygwin'``
728
Mac OS X ``'darwin'``
730
OS/2 EMX ``'os2emx'``
731
====================== ===========================
724
734
:attr:`os.name` has a coarser granularity. :func:`os.uname` gives