Review
Core pattern
Many useful scripts follow this shape:
read input -> compute -> write output
Keep file reading, computation, and file writing separate when possible.
Reading files
Use read mode:
Files provide text. Convert numbers explicitly after reading.
Writing files
Use write mode:
Write mode replaces existing contents. Append mode "a" adds to the end.
Paths
Use pathlib.Path for path construction:
Create folders before writing files inside them:
Path("output").mkdir(exist_ok=True)
Context managers
Use with open(...) as file: so Python closes the file when the block ends.
Keep the block small:
Modules and imports
A module is a Python file. Imports make module names or selected names available:
from pathlib import Path
Avoid from module import * in course code because it hides where names came
from.
Main blocks
Standard script entry-point pattern:
This lets a file define reusable functions and still run as a script.
Small layout
A simple project can use:
project/
data/
output/
tools.py
run.py
Input data, generated output, reusable code, and script workflow should have clear places.