Mental Model: TUI Spreadsheet in Python
A beginner spreadsheet is not a giant table. It’s a dictionary plus rules.
Core Mental Model
Two pieces power the whole tool:
- Storage:
dict[str, str]maps cell key to raw content. - Evaluation: formulas convert raw content into computed values.
Raw content is what users typed. Evaluated value is what users see.
Why dict Is the Right Primitive
Python’s dict is perfect for sparse sheets.
- only store touched cells
- fast lookup by cell name (
A1,B3) - easy save/load serialization
No need for a pre-sized grid when learning fundamentals.
Formula Evaluation as Pipeline
Treat evaluation like a pipeline:
- normalize expression
- split tokens (
left + right) - resolve each token to a number
- compute or return error code
That pipeline mindset transfers directly to parser work later.
Python-Specific Insight
Small helper functions keep complexity down.
normalize_cellprotects the storage boundary_number_valueisolates conversion_evaluatefocuses only on formula logic
This is Pythonic decomposition: small functions, clear intent.
Debugging Order
When value output is wrong, inspect in order:
- normalized key
- stored raw string
- token conversion
- final arithmetic
You’ll usually find the bug quickly.
Good Next Steps
Add one feature at a time:
- subtraction and multiplication
- parentheses support
- circular reference protection
Just keep the same model: store raw, evaluate safely, display clearly.