mirror of
https://github.com/systemd/systemd.git
synced 2024-11-27 12:13:33 +08:00
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:
parent
75c293f37d
commit
baf60a80b5
@ -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())
|
||||||
|
Loading…
Reference in New Issue
Block a user