Get OS pretty name using Python, Raspberry Pi OS

Python 3 exercise run on Raspberry Pi 5 running 64-bit Raspberry Pi OS (bookworm) to read OS pretty name (such as Debian GNU/Linux 12 (bookworm)) by reading and parsing the file "/etc/os-release".

pretty_name.py
with open("/etc/os-release") as f:
    os_release = {}
    for line in f:
        k,v = line.rstrip().split("=")
        os_release[k] = v.strip('"')

for keys, values in os_release.items():
    print(keys, ":", values)

print()
pretty_name = os_release['PRETTY_NAME']
print("PRETTY_NAME:", pretty_name)


Output:
PRETTY_NAME : Debian GNU/Linux 12 (bookworm)
NAME : Debian GNU/Linux
VERSION_ID : 12
VERSION : 12 (bookworm)
VERSION_CODENAME : bookworm
ID : debian
HOME_URL : https://www.debian.org/
SUPPORT_URL : https://www.debian.org/support
BUG_REPORT_URL : https://bugs.debian.org/

PRETTY_NAME: Debian GNU/Linux 12 (bookworm)


Comments

Popular posts from this blog

480x320 TFT/ILI9488 SPI wih EP32C3 (arduino-esp32) using Arduino_GFX Library

my dev.tools - FNIRSI 2C23T 3-in-1 Dual Channel Oscilloscope/Multimeter/Signal Generator