man: prettify line number handling in python example

This way the 'line_number' variable contains the actual line number as we think
of it, instead of adjusting it on output.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2021-11-28 12:30:52 +01:00
parent 75c293f37d
commit baf60a80b5

View File

@ -13,7 +13,7 @@ def read_os_release():
filename = '/usr/lib/os-release' filename = '/usr/lib/os-release'
f = open(filename) f = open(filename)
for line_number, line in enumerate(f): for line_number, line in enumerate(f, start=1):
line = line.rstrip() line = line.rstrip()
if not line or line.startswith('#'): if not line or line.startswith('#'):
continue continue
@ -23,7 +23,7 @@ def read_os_release():
val = ast.literal_eval(val) val = ast.literal_eval(val)
yield name, val yield name, val
else: else:
print(f'{filename}:{line_number + 1}: bad line {line!r}', print(f'{filename}:{line_number}: bad line {line!r}',
file=sys.stderr) file=sys.stderr)
os_release = dict(read_os_release()) os_release = dict(read_os_release())