name = l.split('=', 1)[1]
if name.startswith('"'):
name = name[1:-2].strip()
converts l = 'NAME="Debian GNU/Linux"' into name = 'Debian GNU/Linu' (note the missing 'x'). If this quote-stripping would have gone right, following snippet would remove GNU/Linux:
# work around inconsistent "Debian GNU/Linux" in os-release
if name.endswith('GNU/Linux'):
name = name.split()[0:-1]
but the resulting name variable would be a list of strings then.
Proposed solution: Use shlex to simplify the code to
with open('/etc/os-release') as f:
for l in f:
key, value = shlex.split(l)[0].split('=', 1)
if key == 'NAME':
name = value[:-9].strip() if value.endswith('GNU/Linux') else value
if key == 'VERSION_ID':
version = value
Code like
name = l.split('=', 1)[1] ('"'):
if name.startswith
name = name[1:-2].strip()
converts l = 'NAME="Debian GNU/Linux"' into name = 'Debian GNU/Linu' (note the missing 'x'). If this quote-stripping would have gone right, following snippet would remove GNU/Linux:
# work around inconsistent "Debian GNU/Linux" in os-release 'GNU/Linux' ):
if name.endswith(
name = name.split()[0:-1]
but the resulting name variable would be a list of strings then.
Proposed solution: Use shlex to simplify the code to
with open('/ etc/os- release' ) as f: l)[0].split( '=', 1) 'GNU/Linux' ) else value
for l in f:
key, value = shlex.split(
if key == 'NAME':
name = value[:-9].strip() if value.endswith(
if key == 'VERSION_ID':
version = value