Small Project Layout

A project layout is the arrangement of files and folders in a small program.

For this subject, a simple layout is enough:

word_count/
  data/
    input.txt
  output/
    summary.txt
  word_tools.py
  run_summary.py

The goal is not ceremony. The goal is to make each file's job obvious.

Separate data, output, and code

Use folders for different kinds of files:

Folder or fileJob
data/input files
output/generated files
word_tools.pyreusable functions
run_summary.pyscript that runs the workflow

When generated output is separate from input data, rerunning a script is less confusing.

Keep reusable functions away from file paths

This function is easy to test:

It accepts text and returns a number. It does not know where the text came from.

This script handles paths:

That separation matters. Computation functions should often know as little as possible about the file system.

A tiny complete workflow

Small project workflow in one runnable snippet

Runs locally with Python in your browser.

Ready to run.

The browser runner keeps this inside a temporary file system. The structure is still the same structure you would use on your own machine.

Exercise: Where should generated summaries go?

In the simple layout above, which folder is meant for generated files such as summary.txt?

Answer it first, then check.

HintSeparate inputs from generated results

The layout names one folder for source data and another for program output.

SolutionUse the output folder

Generated files such as summary.txt belong in output/. Keeping them away from data/ prevents a rerun from being mistaken for new input.