The platform module provides an API to obtain information about the base system/platform on which our code runs. Information such as the name of the operating system, the Python version, the architecture, the hardware information, etc. is made public via the functions of the platform module. This module does not need to be installed as it is part of the standard libraries supplied with the Python installation.
We start by importing the platform module.
# python3
>>> Import platform
>> Print output (Module version of the imported platform: , platform.__version__)
Importing the Python platform module
First, let’s take some information about Python, like which version it is, information about how to assemble it, and so on.
- python_version() – Returns the Python version
- python_version_tuple() – Returns the version of python in the autotuple.
- python_build() – Returns the construction number and date as tuple
- python_compiler() is a compiler used to compile python.
- python_implementation() – Returns the implementation of Python such as PyPy, CPython, etc.
>> print(Python version: platform.python_version())>> print(Python tuple version: platform.python_version_tuple())>> print(Build information: platform.python_building())>> print(Compiler information: platform.python_compiler())>> print(Implementation: platform.python_implementation())>> print(Implementation: platform.python_implementation()).
Checking the information in Python
Now let’s take some information about the system, such as the operating system variant, the output version, the processor, etc., and let’s see how it works.
- system() – Returns the name of the system/OS type Linux, Windows, Java.
- version() – Provides information about the system version.
- release() – Returns the system version.
- machine() – Returns the type of machine.
- processor() – Returns the name of the system processor.
- node() – Returns the network name of the system.
- platform() – provides as much useful information about the system as possible.
>>> printing (operating system taste:>> printing (operating system version: platform.version())>> printing (operating system version: platform.release())>> printing (machine type: platform.machine())>> printing (processor: platform.processor())>> printing (network name: platform.nodes())>> printing (Linux kernel version: platform.platform())>> printing (Linux kernel version: platform.platform())
Checking Linux system information
Instead of accessing all system information about the different functions, we can use the uname() function, which gives a name to a tuple with all the information such as system name, version, machine, processor, nodes. We may use index values to access certain information.
>> print(Uname: Function platform.uname())
>> print(nSystem information: platform.uname()[0]).
>>> print(nName of network) : Platform.uname() [1]).
>> Printing (nOS share) : Platform.uname() [2]).
>>> print(nOS version: platform.uname()[3]).
>>> print(nMachine Type: platform.uname()[4]).
>> print(nMachine Processor: platform.uname()[5]).
Think of a use case where you only want to run your program in a certain version of Python or only in a certain version of the operating system, in this case the platform module is very useful.
Here is an example of a pseudo-code to check the Python version and the taste of the operating system.
Platform import systems
as platform.python_version_tupel()[0] == 3 :
< Code block >
other:
sys.exit()
as platform.uname()[0].lower() == linux :
< Code block >
other:
sys.exit()
Python moduleKeyword
Each programming language has integrated keywords that offer different functionalities. For example: I mean, it’s a lie if, for example… Similarly, Python has built-in keywords that cannot be used as identifiers for variables, functions or classes.
The keyword module offers 2 functions.
- kwlist – Prints a list of embedded keywords.
- iskeyword(s) – returns where if s is the keyword defined by Python
Keyword module on Python
Now that we have reached the end of the article, we have discussed 2 Python modules (platform and keyword). The platform module is very useful if we want to get information about the system we work with. On the other hand, the keyword module provides a list of built-in keywords and functions that can be used to check whether a particular identifier is a keyword or not.
If you like what we do here at TecMint, you should think:.
TecMint is the fastest growing and most reliable community site for all articles, guides and books about Linux on the web. Millions of people visit TecMint! to find or consult thousands of published articles that are accessible to everyone for FREE.
If you like what you read, consider buying us a coffee (or 2) as a thank you.
Thank you for your continued support.
Related Tags:
python import module from directory,python modules list,python import function from file,create python package,packages in python,python importlib,python libraries list,python libraries download,python libraries for data science,python documentation pdf,python libraries for machine learning,python 3 specification,sys python,sys module in python – geeksforgeeks,pip install sys,object serialization in python,math module in python,python get module name,how do you handle missing keys,types of modules in python,why python strings is called two-way indexing,to install numpy in the system we use command,generator expressions use _______ brackets.