get system architecture in python

To get the system architecture in Python, you can use the platform module. The platform module provides a way to retrieve the system's hardware and OS details, including the architecture.

Here's an example code snippet to get the system architecture using platform:

main.py
import platform

# get the system's architecture
arch = platform.architecture()[0]

print("System architecture:", arch)
120 chars
7 lines

The platform.architecture() function returns a tuple containing two elements: the first element is the system's architecture (such as "32bit" or "64bit"), and the second element is the Python interpreter's build information (such as "MSC v.1916 32 bit (Intel)"). In this case, we only need the first element, so we use the [0] index to access it.

This code will output something like:

main.py
System architecture: 64bit
27 chars
2 lines

gistlibby LogSnag