• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • Home
  • Learn to Code
    • Python
    • JavaScript
  • Code Snippets
    • HTML
    • JavaScript
    • jQuery
    • PHP
    • Python
    • SAS
    • Ruby
  • About
You are here: Home / Python / Python Get Operating System Information with os and platform Modules

Python Get Operating System Information with os and platform Modules

February 24, 2022 Leave a Comment

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.

Other Articles You'll Also Like:

  • 1.  Find Quotient and Remainder After Division in Python
  • 2.  pandas variance – Compute Variance of Variables in DataFrame
  • 3.  Using Python To Split String by Comma into List
  • 4.  Solve Python Object Does Not Support Indexing Error
  • 5.  Check if Variable is String in Python
  • 6.  Using Python to Insert Tab in String
  • 7.  Using readlines() and strip() to Remove Spaces and \n from File in Python
  • 8.  Random Number Without Repeating in Python
  • 9.  Using GroupBy() to Group Pandas DataFrame by Multiple Columns
  • 10.  Length of Tuple Python – Find Tuple Length with Python len() Function

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

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

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy