How to detect OS with Python?

Question:

How can I do in Python to identify which operating system is being used?

Answer:

import os
print(os.name)

This is usually what matters, indicating what you can and cannot use in your application.

If you really want to show someone what the operating system is or if you want to do something very specific for a specific version then you can use:

import platform
print(platform.system())
print(platform.release())

See working on ideone . And on repl.it. Also posted on GitHub for future reference .

Scroll to Top