A Python project – A modular project (code organisation)


Lesson 10 of 15 · Python projects

This is a key step towards writing professional code.

In this project you will learn how to organise a Python application using modules and several files.

Instead of one big file, we will split the code into logical parts.

Modular programming means:
  • smaller and clearer code
  • easier maintenance
  • reusing functions

Why is modular programming important?

Large programs become hard to follow if they are in one file.

That is why we use modules — smaller pieces of code that each solve one problem.

  • easier debugging
  • better organisation
  • teamwork
The principle: "divide the problem into smaller parts".

Project structure


project/
│
├── main.py
├── math_utils.py
├── file_utils.py

1. A module for maths


# math_utils.py

def add(a, b):
    return a + b

def subtract(a, b):
    return a - b

2. A module for working with files


# file_utils.py

def save_result(result):
    with open("result.txt", "w") as f:
        f.write(str(result))

3. The main program


# main.py

from math_utils import add
from file_utils import save_result

result = add(10, 5)

print("Result:", result)

save_result(result)

How does this work?

  • import connects the files
  • each file has its own role
  • the main program uses the modules
This is the basis of all larger applications — web, games, backend systems.

Common mistakes

  • ❌ a wrong file name
  • ❌ a forgotten import
  • ❌ a clash of function names
  • ❌ not all files are in the same folder

How can you extend the project?

  • add more modules
  • make folders (packages)
  • add a configuration file
  • make a CLI application
Advanced projects have dozens of files — this is the first step towards that.

Mini challenges

  • Add a function for multiplication
  • Add reading from a file
  • Organise the code into a folder (package)

Where is the modular approach used?

  • web applications
  • backend systems
  • games
  • data science projects

Modularity makes it possible to develop larger and more complex systems.


Related lessons


Frequently asked questions

What is a module in Python?

A file that contains Python code and functions we can reuse.

Why use several files?

Because the code is clearer and easier to maintain.

When should I start with modular code?

As soon as the project grows beyond one file.


How to make the project your own:
1) first run the given code without changes, 2) change one thing and predict what will happen, 3) add at least one feature of your own, 4) write down in a notebook what you changed and why. A work log like that is the basis of a creative programming paper.