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

MicroPython/ESP32-C3 + 1.8" 128x160 TFT ST7735 SPI, using boochow/MicroPython-ST7735 library.

CameraWebServe: ESP32-S3 (arduino-esp32) + OV5640 camera module