Python Glossary Русский

all Python 3systerm

sys.platform

information

The platform identifier: 'linux', 'darwin' on macOS, 'win32' on Windows — even 64-bit Windows.

Syntax

sys.platform.startswith('linux')

Check it with startswith: older Linux versions gave 'linux2' and FreeBSD gives 'freebsd14'. The value is fixed when the interpreter is built, so it suits choosing a code branch. For machine details use the platform module; os.name only distinguishes 'posix' and 'nt'.

Examples

import sys
print(sys.platform)  # → ? linux, darwin или win32
if sys.platform.startswith('win'):
    newline = '\r\n'
else:
    newline = '\n'
print(sys.platform in {'linux', 'darwin', 'win32'} or sys.platform.startswith('freebsd'))  # → ? True на распространённых системах

See also

Open in the full glossarydocs.python.orgReport an inaccuracy