Retrieve and Display System Information with Simple Scripts
In this blog, we will see how to get the system information using the Python Platform module. We will read the operating system name, host name, release number, system’s version, hardware-type and processor details.
Platform module
The platform module is a predefined library in python. So, we need not to install it from any third party source.
Link to know more about platform module: https://docs.python.org/3/library/platform.html
This module provides a information about the platform on which the program is being currently executed like OS, node, OS version, Version, etc.
import platform module
We have to import a platform module to invoke all the properties of it.
Code
There are two methods to get a system info, 1. Using individual methods. 2. Using uname method.
- platform.machine() displays the machine type.
- platform.node() that displays the information about the system’s network name.
- platform.processor() that displays the information about the platform processor.
- platform.system() displays the name of the operation system that currently working.
Method 1
import platform print('********** using individual method *********','\n') print("Operating System : ", platform.system()) print("Host-name : " , platform.node()) print("Machine : ", platform.machine()) print("Processor : ", platform.processor()) print("Release : ", platform.release()) print("Version : ", platform.version())
Output
********** using individual methods ********* Operating System : Linux Host-name : a89a8e7c499f Machine : x86_64 Processor : x86_64 Release : 5.4.104+ Version : #1 SMP Sat Jun 5 09:50:34 PDT 2021
Method 2
import platform data = platform.uname() print('********** using uname method *********','\n') print("Operating System : ", data.system()) print("Host-name : " , data.node()) print("Machine : ", data.machine()) print("Processor : ", data.processor()) print("Release : ", data.release()) print("Version : ", data.version()) ''' print(platform.uname()) It returns the same results in list '''
Output
********** using uname method ********* Operating System : Linux Hostname : a89a8e7c499f Machine : x86_64 Processor : x86_64 Release : 5.4.104+ Version : #1 SMP Sat Jun 5 09:50:34 PDT 2021
Related Post
What is python turtle graphics and its commands: https://iterathon.tech//what-is-python-turtle-graphics-and-its-commands/
How to design Instagram Logo using python: https://iterathon.tech//how-to-design-instagram-logo-using-python/
How to Impress a girl’s heart using python heart: https://iterathon.tech//how-to-impress-a-girlfriend-heart-using-python/
Learn Something New ❣