Hello, reader! In this article, we will be focusing on Python Platform Module – 7 IMP functions that we should know! So, let us begin! 🙂
Python Platform Module – Overview
Python offers us various modules to deal with the data and perform necessary manipulations. One such module is Python Platform Module.
With the Platform module, we can retrieve all the necessary and available information about the system on which we run the program that moment. Thus, we can fetch data available about the operating system, node, version of python being used, etc.
This module is useful when we need to identify if the hardware specifications are good to go with the program or if it needs alteration.
Make use of the pip command to install platform module-
pip install platform
Having understood about the module, we can now focus some of the mostly used functions provided by the platform module.
1. Details about the processor
The platform.processor() method enables us to fetch the details of the processor on which the program runs. It represents the name as well as the model of the processor.
import platform print('Processor details of the platform:', platform.processor())
Processor details of the platform: Intel64 Family 6 Model 142 Stepping 9, GenuineIntel
2. Machine Type details
We can make use of platform.machine() function which helps us to get the machine details i.e. details about the size of the underlying registers from the machine on which the program runs.
import platform print('Machine details:', platform.machine())
Machine details: AMD64
3. Architecture details
With Platform module, we can easily fetch the architecture details of the system on which the code runs.
The platform.architecture() function fetches the details of the architecture level i.e. the bits and returns the following:
- The number of bits in the processor.
- The linkage format for the processor
import platform print('Platform Architecture:', platform.architecture())
Platform Architecture: ('64bit', 'WindowsPE')
4. Node and Platform details
- With the node() function, we can easily retrieve the network name of the node/system.
- The platform() function helps us fetch information about the platform on which the code runs.
import platform print('Node details:', platform.node()) print('Platform details:', platform.platform())
As seen below, we get the OS details as the platform details on which the code runs. Further, the model of the system on which the code resides is returned by the node() function.
Node details: LAPTOP-MV9CEQNU Platform details: Windows-10-10.0.18362-SP0
5. Processor and System details
With every system, the outcome of the current system varies. The processor() function helps us get the processor details of the system on which the code runs. While the system() function helps us get the Operating system-level information i.e. the name of the operating system.
import platform print('Processor details:', platform.processor()) print('System details:', platform.system())
Processor details: Intel64 Family 6 Model 142 Stepping 9, GenuineIntel System details: Windows
6. Python build details
With the python_build() function, we can fetch the information regarding the build date and the build number for python on the platform. The result stays specific to the system on which the code runs.
import platform print('Build details:', platform.python_build())
Build details: ('v3.6.5:f59c0932b4', 'Mar 28 2018 17:00:18')
7. Python Compiler details
With python_compiler() function, we can fetch and represent the name of the compiler that is used to compile and run the python programs on the specific system.
import platform print('Compiler details:', platform.python_compiler())
Compiler details: MSC v.1900 64 bit (AMD64)
Feel free to comment below, in case you come across any questions. For more such posts related to Python programming, Stay tuned with us. Till then, Happy Learning!! 🙂