65
loading...
This website collects cookies to deliver better user experience
NAME="Ubuntu"
VERSION="20.04.3 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.3 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
csv
library. Below is a code snippet which parses /etc/os-release and returns a dictionary.import csv
import pathlib
from pprint import pprint
path = pathlib.Path("/etc/os-release")
with open(path) as stream:
reader = csv.reader(stream, delimiter="=")
os_release = dict(reader)
pprint(os_release)
{'BUG_REPORT_URL': 'https://bugs.launchpad.net/ubuntu/',
'HOME_URL': 'https://www.ubuntu.com/',
'ID': 'ubuntu',
'ID_LIKE': 'debian',
'NAME': 'Ubuntu',
'PRETTY_NAME': 'Ubuntu 20.04.3 LTS',
'PRIVACY_POLICY_URL': 'https://www.ubuntu.com/legal/terms-and-policies/privacy-policy',
'SUPPORT_URL': 'https://help.ubuntu.com/',
'UBUNTU_CODENAME': 'focal',
'VERSION': '20.04.3 LTS (Focal Fossa)',
'VERSION_CODENAME': 'focal',
'VERSION_ID': '20.04'}
csv
library to read it and specify the equal sign as fields delimiters.reader
will yield a list of (key, value) tuplesdict
built-in turns that list of tuples into a dictionary