MCPcopy Create free account
hub / github.com/dabeaz-course/python-mastery / print_table

Function print_table

Solutions/3_3/tableformat.py:4–17  ·  view source on GitHub ↗
(records, fields)

Source from the content-addressed store, hash-verified

2
3# Print a table
4def print_table(records, fields):
5 # Print the table headers in a 10-character wide field
6 for fieldname in fields:
7 print('%10s' % fieldname, end=' ')
8 print()
9
10 # Print the separator bars
11 print(('-'*10 + ' ')*len(fields))
12
13 # Output the table contents
14 for r in records:
15 for fieldname in fields:
16 print('%10s' % getattr(r, fieldname), end=' ')
17 print()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected