The main way to identify the current OS is to use
process.platform
(or the identical
os.platform()).
The os core module offers some finer-grained
identification methods but those are rarely needed:
os.type()is similar but slighly more precise.os.release()returns the OS version number, e.g.3.11.0-14-generic(Linux),18.0.0(Mac) or10.0.17763(Windows).os.version()returns a more detailed OS version number, e.g.#32-Ubuntu SMP Fri Jan 31 20:24:34 UTC 2020(Linux),Darwin Kernel Version 18.0.0: Wed Aug 22 20:13:40 PDT 2018; root:xnu-4903.201.2~1/RELEASE_X86_64(Mac) orWindows 10 Home(Windows).os.arch()(or the identicalprocess.arch) returns the CPU architecture, e.g.armorx64.os.endianness()returns the CPU endianness, i.e.BEorLE.navigator.platformcan also be used, which combinesprocess.platformandprocess.arch.
Some projects allow retrieving:
getos: the Linux distribution name.osname(and the relatedwindows-releaseandmacos-release): the OS name and version in a human-friendly way.is-windows: whether current OS is Windows, including through MSYS and Cygwin.is-wsl: whether current OS is Windows though WSL.
When using OS-specific logic, identify the current OS with
process.platform.
Next (ποΈ System configuration)
Previous (ποΈ System)
Top