In Python, the os and platform modules have many useful functions which allow us to get operating system information easily.
import os
import platform
print(os.name)
print(platform.system())
print(platform.release())
print(platform.platform())
#Output:
nt
Windows
10
Windows-10-10.0.22000-SP0
In Python, the os and platform modules have provide us with many useful functions which allow us to get information about the operating system the code is running on.
We can get the name of the operating system dependent module imported with the os name property.
The name property returns values such as ‘posix’,’nt’,’os2′,’ce’,’java’, and ‘riscos’ where, for example, ‘nt’ is a Windows operating system.
The platform module provides us with a number of great functions which give us operating system information.
For example, the system() function gives us the operating system, the release() function gives us the version of the operating system, and the platform() function gives us a string identifying the underlying platform with as much useful information as possible.
Below is an example of how to get various pieces of operating system info with Python.
import os
import platform
print(os.name)
print(platform.system())
print(platform.release())
print(platform.platform())
#Output:
nt
Windows
10
Windows-10-10.0.22000-SP0
Hopefully this article has been useful for you to learn how to get operating system information with the Python os module.