Python

How to detect the operating system with Python

April 16, 2022

How to detect the operating system with Python

In this article you will learn how to detect the operating system with Python – so you know if the user is using Windows, Linux or something else!

detect the operating system with Python thumb

Hey you all programmers, ok? Let’s learn more about the features that Python provides us!

To detect a user’s operating system is very easy with Python, we just need to use the lib os

With it, the name property gives us the name of the operating system being used, let’s see an example:

import os

print(os.name)

Through this print, the user’s OS will be displayed on the console

If you need more details, you can also use the platform library

With this you can even get the version of the Operating System

Let’s see one practical example:

import platform

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

Witch system you have the name of the OS, and with release you get the version it is in, cool, right?

With these libraries and information it is possible to perform any OS checks on the user machine of the software you are programming.

Conclusion

In this article we learned how to detect the operating system in Python language

We use two libraries: os and platform

The platform gives us more detailed data, such as the OS version

It returns us only the name of the same

Do you want to learn more about Python? Click here!

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x