get system platform in python

To retrieve the system platform in Python, you can use the platform module in conjunction with the os module. The platform.system() function will return the name of the operating system, while the platform.release() function will return the version of the operating system.

Alternatively, you can use the os.uname() function to retrieve detailed information about the system, including the operating system name and version.

Here's an example of how to use these functions:

main.py
import platform
import os

# retrieve the system platform
print("Operating system:", platform.system())
print("Operating system version:", platform.release())

# alternatively, use os.uname() to retrieve more detailed information
uname = os.uname()
print("System name:", uname.sysname)
print("Node name:", uname.nodename)
print("Release:", uname.release)
print("Version:", uname.version)
print("Machine:", uname.machine)
print("Processor:", uname.processor)
458 chars
16 lines

This code will output something like:

main.py
Operating system: Windows
Operating system version: 10

System name: Linux
Node name: my-machine
Release: 5.10.0-8-amd64
Version: #1 SMP Debian 5.10.46-4 (2021-08-03)
Machine: x86_64
Processor: x86_64
201 chars
10 lines

related categories

gistlibby LogSnag