Platform Module¶
Indices and tables¶
Introduction¶
Sometimes for your module or application to execute correctly, it must learn about the hardware and software it is running on top of and then adjust its behavior appropriately. The platform
module can assist with obtaining this information.
The platform
module is comprised only of functions (no constants or classes) which return the desired information. A series of (non-exhaustive) examples will best describe what is available:
Note
Some information can be obtained by more than one function.
Obtain architecture information
>>> import platform >>> platform.architecture() ('64bit', 'ELF') >>> platform.machine() 'x86_64' >>> platform.processor() 'x86_64'
Obtain the hostname:
>>> platform.node() 'mike-dt'
Obtain information about Python:
>>> platform.python_build() ('default', 'Mar 22 2017 12:26:13')
>>> platform.python_implementation() 'CPython'
>>> platform.python_version() '3.4.6'
>>> platform.python_version_tuple() ('3', '4', '6')
Obtain information about the OS:
>>> platform.release() '4.4.103-18.41-default'
>>> playform.system() 'Linux'
>>> platform.version() '#1 SMP Wed Dec 13 14:06:33 UTC 2017 (f66c68c)'
>>> platform.uname() uname_result(system='Linux', node='mike-dt', release='4.4.103-18.41-default', version='#1 SMP Wed Dec 13 14:06:33 UTC 2017 (f66c68c)', machine='x86_64', processor='x86_64')
>>> platform.linux_distribution() ('openSUSE ', '42.2', 'x86_64')
Tip
Use
platform.win32_ver()
andplatform.mac_ver()
to get information specific to those operating systems.Misc information
>>> platform.java_ver() ('', '', ('', '', ''), ('', '', ''))
>>> platform.libc_ver() ('glibc', '2.3.4')