Thomas Eapen · Selected work
Putting a reporting method behind a clear command
Typed options, useful defaults and built-in help turn an analysis function into a reproducible command.
Synthetic example · independently invented dataOne-page print edition · A3 landscape
- 01 · ChooseSelect a view and a threshold.
- 02 · ValidateReject invalid choices before processing.
- 03 · ReportApply the same rule to the same synthetic rows.
SYNTHETIC INPUT / THREE GROUPS
A small exception report
| Group | Planned | Observed | Difference |
|---|---|---|---|
| Group A | 60 | 63 | +3 |
| Group B | 75 | 71 | -4 |
| Group C | 90 | 91 | +1 |
ACTUAL DEMONSTRATION INVOCATION AND OUTPUT
report --threshold 2 --view exceptions
Group A: +3 units
Group B: -4 units--thresholdaccepts non-negative integers; the default is 2.--viewacceptsallorexceptions.--helpdescribes the options and their defaults.
THE METHOD / PYTHON
A new Click command
import click
@click.command()
@click.option('--threshold', type=click.IntRange(min=0),
default=2, show_default=True)
@click.option('--view', type=click.Choice(['all', 'exceptions']),
default='exceptions', show_default=True)
def report(threshold, view):
"""Summarise the three built-in synthetic rows."""
for row in CLI_ROWS:
delta = row['observed'] - row['planned']
if view == 'all' or abs(delta) > threshold:
click.echo(f"{row['group']}: {delta:+d} units")Selected code from the new demonstration that computes these results.
Separate the interface from the records CLI_ROWS contains the three invented rows shown above. A difference is reported when its absolute value is greater than the threshold. Group C is omitted because its difference is only +1.