๐ŸŽ›๏ธ OS identification

April 14, 2024 ยท View on GitHub

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) or 10.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) or Windows 10 Home (Windows).
  • os.arch() (or the identical process.arch) returns the CPU architecture, e.g. arm or x64.
  • os.endianness() returns the CPU endianness, i.e. BE or LE.
  • navigator.platform can also be used, which combines process.platform and process.arch.

Some projects allow retrieving:

Summary

When using OS-specific logic, identify the current OS with process.platform.


Next (๐ŸŽ›๏ธ System configuration)
Previous (๐ŸŽ›๏ธ System)
Top