Tutorials

Photo of Ambrosio “Butch” U. Mahinay

Python for Treasury Work

Short, practical Python lessons built around the daily work of a local treasury office: receipts, collections, penalties, reports and audit trails. Every example uses made-up data, runs as written, and shows the output it really prints. I am learning alongside you, so the lessons grow from simple scripts to the tools I use in building software.

Where to begin. New to Python? Start with Lesson 0. It shows how to install Python, run a script, and fix the errors almost everyone meets on the first day. Then take the lessons in order; each one builds on the one before.

Our promise. Every lesson is checked before it goes live: the code is run, the output you see is what it really prints, the facts and laws are checked against sources, and the page is reviewed on phone and computer. Each lesson shows the month it was last checked.

Words to know

Script
A text file of Python code, saved with the .py ending, that you run from start to finish.
Variable
A name that holds a value, like receipts = 10. You can change it later.
Loop
Code that repeats for each item, written with for. It is how a script goes through every row of a file.
Function
A named set of steps you can reuse, written with def. You give it inputs and it gives back a result.
Module
A file of ready-made code you bring in with import, such as csv or decimal.
CSV
Comma-separated values: a plain text table, one row per line, that Excel and most systems can export.
List
An ordered collection, written with square brackets: [7650101, 7650102].
Dictionary
Pairs of keys and values, written with braces: {"General Fund": 21986.15}. You look a value up by its key.
Set
A collection with no repeats and no order. Good for comparing what you have with what you expected.
Decimal
A number type that keeps peso amounts exact, so centavos never drift.
f-string
Text that starts with f and fills in values inside braces: f"Total: {total}".
DataFrame
The table that the pandas library works with: rows and named columns, like a sheet in Excel.
Library
A collection of modules someone else wrote, such as pandas. Some come with Python; others you install.
pip
Python's installer for extra libraries: pip install pandas.
Hash
A short fingerprint of some data. Change one character and the fingerprint changes completely.
HMAC
A hash made with a secret key. Only someone with the key can make a matching one.

New lessons are added regularly. All names, receipt numbers and amounts in the examples are made up.