Platform Module in Python.pdf

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

Platform Module in Python Object Oriented Programming 1 284CIS-3 Saud Alshahrani 1 Platform Module in Python Python defines an in-built module platform that provides system information. The Platform module is used to r...

Platform Module in Python Object Oriented Programming 1 284CIS-3 Saud Alshahrani 1 Platform Module in Python Python defines an in-built module platform that provides system information. The Platform module is used to retrieve as much possible information about the platform on which the program is being currently executed. information about the device, it’s OS, node, OS version, Python version, etc. This module plays a crucial role when you want to check whether your program is compatible with the python version installed on a particular system or whether the hardware specifications meet the requirements of your program. 2 Platform Module in Python 1. platform.platform() Purpose: Returns a string with a detailed description of the platform. Description: This function gives you a complete summary of the platform you are running on, which includes information like OS name, release, version, and additional identifiers. Example: import platform print(platform.platform()) Output: 'Windows-10-10.0.19041-SP0' # on a Windows 10 system 3 Platform Module in Python 2. platform.machine() Purpose: Returns the machine type (architecture). Description: This provides the hardware identifier of the machine, such as x86_64 for 64-bit Intel processors, arm for ARM-based systems, etc. Example: print(platform.machine()) Output: 'x86_64' # for a 64-bit architecture 4 Platform Module in Python 3- platform.processor() Purpose: Returns the name of the processor. Description: This function returns the processor type of the machine you are working on. If the information is not available, it may return an empty string. Example: print(platform.processor()) Output: 'Intel64 Family 6 Model 158 Stepping 10, GenuineIntel' 5 Platform Module in Python 4. platform.system() Purpose: Returns the name of the operating system. Description: This function provides a simple way to check the underlying OS. The output might be Windows, Linux, Darwin (for macOS), etc. Example: print(platform.system()) Output: 'Windows' 6 Platform Module in Python 5. platform.version() Purpose: Returns the version of the operating system. Description: This function returns the version information of the current operating system. Example: print(platform.version()) Output: '10.0.19041' # for Windows 10 7 Platform Module in Python 6-platform.python_implementation() Purpose: Returns the name of the Python implementation. Description: This function tells you which Python interpreter is being used, such as CPython, PyPy, IronPython, etc Example: print(platform.python_implementation()) Output: 'CPython' # for the standard Python implementation 8 Platform Module in Python 7-platform.python_version_tuple() Purpose: Returns the Python version as a tuple. Description: This function returns the current version of Python as a tuple, which is useful when you want to split the major, minor, and patch versions. Example: print(platform.python_version_tuple()) Output: ('3', '9', '7') # example for Python version 3.9.7 9 Platform Module in Python 8-platform.uname() This function returns a tuple that stores information regarding the system. Basically this function can be used to replace the individual functions to retrieve information about the system, node, release, version, machine, version and processor. Thus, a single function serving many purposes Example: print('system information:', platform.uname()) Output: system information: uname_result(system='Windows', node='sag_', release='11', version='10.0.22631', machine='AMD64') 10 Platform Module in Python 9-platform.python_build() This function returns a tuple that stores information about the python build date and build no. This information is stored in the tuple as a string datatype. Example: print('version no and date of manufacturing:', platform.python_build()) Output: version no and date of manufacturing: ('tags/v3.12.6:a4a2d2b', 'Sep 6 2024 20:11:23') 11 10-platform.architecture() This function returns a tuple that stores information about the bit architecture(number of bits in the platform processor) and linkage format( defines how names can or can not refer to the same entity throughout the whole program or one single translation unit). Example: print('Platform architecture:', platform.architecture()) Output: Platform architecture: ('64bit', 'WindowsPE') 12 Platform Module in Python These functions in the platform module provide various ways to get detailed information about the system environment (like OS, hardware, and processor), and the Python runtime itself (like version and implementation). This is often useful for debugging, logging, or for ensuring compatibility in multi-platform applications. 13 Thanks 14

Use Quizgecko on...
Browser
Browser