views.py now uses enumerate() to be more Pythonic.

This commit is contained in:
Chris Palmer 2020-11-29 12:21:38 +00:00
parent 18ff4c6d46
commit 17b12c7f31
1 changed files with 3 additions and 6 deletions

View File

@ -308,8 +308,7 @@ def views(target, do_assemblies = None):
if printed: if printed:
print('### 3D Printed parts', file = doc_file) print('### 3D Printed parts', file = doc_file)
keys = sorted(list(printed.keys())) keys = sorted(list(printed.keys()))
for i in range(len(keys)): for i, p in enumerate(keys):
p = keys[i]
print('%s %d x %s |' % ('\n|' if not (i % 3) else '', printed[p]["count"], p), file = doc_file, end = '') print('%s %d x %s |' % ('\n|' if not (i % 3) else '', printed[p]["count"], p), file = doc_file, end = '')
if (i % 3) == 2 or i == len(printed) - 1: if (i % 3) == 2 or i == len(printed) - 1:
n = (i % 3) + 1 n = (i % 3) + 1
@ -324,8 +323,7 @@ def views(target, do_assemblies = None):
if routed: if routed:
print("### CNC Routed parts", file = doc_file) print("### CNC Routed parts", file = doc_file)
keys = sorted(list(routed.keys())) keys = sorted(list(routed.keys()))
for i in range(len(keys)): for i, r in enumerate(keys):
r = keys[i]
print('%s %d x %s |' % ('\n|' if not (i % 3) else '', routed[r]["count"], r), file = doc_file, end = '') print('%s %d x %s |' % ('\n|' if not (i % 3) else '', routed[r]["count"], r), file = doc_file, end = '')
if (i % 3) == 2 or i == len(routed) - 1: if (i % 3) == 2 or i == len(routed) - 1:
n = (i % 3) + 1 n = (i % 3) + 1
@ -340,8 +338,7 @@ def views(target, do_assemblies = None):
if sub_assemblies: if sub_assemblies:
print("### Sub-assemblies", file = doc_file) print("### Sub-assemblies", file = doc_file)
keys = sorted(list(sub_assemblies.keys())) keys = sorted(list(sub_assemblies.keys()))
for i in range(len(keys)): for i, a in enumerate(keys):
a = keys[i]
print('%s %d x %s |' % ('\n|' if not (i % 3) else '', sub_assemblies[a], a), file = doc_file, end = '') print('%s %d x %s |' % ('\n|' if not (i % 3) else '', sub_assemblies[a], a), file = doc_file, end = '')
if (i % 3) == 2 or i == len(keys) - 1: if (i % 3) == 2 or i == len(keys) - 1:
n = (i % 3) + 1 n = (i % 3) + 1