tabulate is a Python library that turns iterable rows, such as tuples parsed from CSV data, into readable text tables. Pass rows to tabulate(), then provide headers when the output needs column names. section 19.1.6
Formatting workout data
>>> from tabulate import tabulate >>> wod = [('Pushups', 56), ('Situps', 88), ('Crunches', 27), ('Burpees', 35)] >>> print(tabulate(wod, headers=('Exercise', 'Reps'))) Exercise Reps ---------- ------ Pushups 56 Situps 88 Crunches 27 Burpees 35 section 19.1.6
A small CSV-driven program can use tabulate in this sequence:
- Install tabulate directly or include it in requirements.txt. section 19.1.1
- Parse each input row with csv.DictReader(), split the reps range, and convert its bounds to integers. section 19.1.8
- Select exercises and random repetition counts, then pass the resulting rows to tabulate() for terminal output. section 19.1.8
- Test missing or malformed data rather than assuming every delimited field is valid. section 19.5
>>> print(tabulate(wod, headers=('Exercise', 'Reps')))
Exercise Reps
---------- ------
Pushups 56
Situps 88
Crunches 27
Burpees 35
Browse the rendered table showing named Exercise and Reps columns. section 19.1.6
