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".
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
Post a Comment