Developers many times need to determine information about the underlying system on which software is running like machine type, OS version, architecture, processor, python build details, etc. This kind of information can be used to make decisions about software configuration based on the underlying system. Python provides us with a module named platform which has a list of methods that provides information about the underlying system. As a part of this tutorial, we'll explain methods provided by platform module whose knowledge can be useful to developers.
We'll start by importing the platform module.
import platform
bits, linkage = platform.architecture(bits="", linkage="")
print("Processor Type : {}".format(bits if bits else "Not Found"))
print("Linkage : {}".format(linkage if linkage else "Not Found"))
machine = platform.machine()
print("Machine : {}".format(machine))
node_name = platform.node()
print("Node Name of Computer in Network : {}".format(node_name))
platform_details = platform.platform()
print("Platform Details : {}".format(platform_details))
platform_details = platform.platform(terse=True)
print("Platform Details : {}".format(platform_details))
processor = platform.processor()
print("Processor Details : {}".format(processor))
If you are interested in learning about Python's configuration details then please feel free to check out the tutorial on Python module sysconfig which provides methods for it.
build_no, build_date = platform.python_build()
print("Python Build : Build No - {}, Build Date : {}".format(build_no, build_date))
compiler = platform.python_compiler()
print("Python Compiler : {}".format(compiler))
python_implementation = platform.python_implementation()
print("Python Implementation : {}".format(python_implementation))
python_revision = platform.python_revision()
print("Python Revision : {}".format(python_revision if python_revision else "NA"))
python_version = platform.python_version()
major,minor,patch = platform.python_version_tuple()
print("Python Version : {}".format(python_version))
print("Python Version : Major-{},Minor-{},Patch-{}".format(major,minor,patch))
release_info = platform.release()
print("System Release Information : {}".format(release_info))
system = platform.system()
print("System : {}".format(system))
sys_version = platform.version()
print("System Version : {}".format(sys_version))
system_details = platform.uname()
print("System Details Instance Type : {}".format(type(system_details)))
print("System : {}".format(system_details.system))
print("Node Name : {}".format(system_details.node))
print("Release Details : {}".format(system_details.release))
print("Version Details : {}".format(system_details.version))
print("Machine Details : {}".format(system_details.machine))
print("Processor Details : {}".format(system_details.processor))
sys_alias = platform.system_alias(platform.system(), platform.release(), platform.version())
print("System Alias : {}".format(sys_alias))
c_name, c_ver = platform.libc_ver()
print("GCC Details : {}-{}".format(c_name,c_ver))
Please make a NOTE that the below-mentioned methods will work only on systems that are mentioned in their names.
This ends our small tutorial explaining methods of platform module. Please feel free to let us know your views in the comments section.
If you are more comfortable learning through video tutorials then we would recommend that you subscribe to our YouTube channel.
When going through coding examples, it's quite common to have doubts and errors.
If you have doubts about some code examples or are stuck somewhere when trying our code, send us an email at coderzcolumn07@gmail.com. We'll help you or point you in the direction where you can find a solution to your problem.
You can even send us a mail if you are trying something new and need guidance regarding coding. We'll try to respond as soon as possible.
If you want to