Categories
Python Answers

How to check what OS a script is running on with Python?

Spread the love

Sometimes, we want to check what OS a script is running on with Python.

In this article, we’ll look at how to check what OS a script is running on with Python.

How to check what OS a script is running on with Python?

To check what OS a script is running on with Python, we can use the platform module.

For instance, we write

import platform

s = platform.system()
r = platform.release()

to call platform.system to get the OS name.

And we call platform.release to get the kernel version.

Conclusion

To check what OS a script is running on with Python, we can use the platform module.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *