python-mastery/Solutions/3_2/tableformat.py

9 lines
282 B
Python
Raw Normal View History

2023-07-17 03:21:00 +02:00
# tableformat.py
# Print a table
def print_table(records, fields):
print(' '.join('%10s' % fieldname for fieldname in fields))
print(('-'*10 + ' ')*len(fields))
for record in records:
print(' '.join('%10s' % getattr(record, fieldname) for fieldname in fields))