"""Bank reconciliation that prints every step, not only the difference. Sample for the article "Show the working" on https://auditablecode.com/articles/show-the-working The figures in bank-rec-demo.csv are made up. Run with both files in one folder: python bank_rec.py Or point it at your own file: python bank_rec.py my-rec.csv """ import csv import sys from decimal import Decimal as D from pathlib import Path path = Path(sys.argv[1]) if len(sys.argv) > 1 else Path(__file__).with_name("bank-rec-demo.csv") with open(path, newline="", encoding="utf-8") as f: v = {row["item"]: D(row["amount"]) for row in csv.DictReader(f)} # amounts read as text, never float bank, unpresented, in_transit = v["bank"], v["unpresented"], v["in_transit"] ledger, charges = v["ledger"], v["charges"] adj_bank = bank - unpresented + in_transit adj_ledger = ledger - charges print(f"Bank {bank} - unpresented {unpresented} + in transit {in_transit} = {adj_bank}") print(f"Ledger {ledger} - charges {charges} = {adj_ledger}") print(f"Difference {adj_bank - adj_ledger}")