My App
Phase 6 — Exceptions + Modules

Modules & Imports

How Python files talk to each other — no export keyword needed

Every file is a module

In JS/TS, a file only shares something if you explicitly export it:

// users.js
export function getUser() {
  // ...
}
// main.js
import { getUser } from './users.js';

In Python, every .py file is automatically a module — anything defined at the top level (functions, classes, variables) can be imported by another file, with no export keyword at all:

# users.py
def get_user():
    ...
# main.py
from users import get_user

The module's name is just the filename without .pyusers.py becomes the module users.

Two ways to import

Import a specific name — use it directly, no prefix:

from users import get_user

get_user()

Import the whole module — access everything through its name:

import json

json.dumps({"name": "John"})

This second style maps to JS's namespace import:

import * as fs from 'fs';

fs.readFileSync('file.txt');

json here is one of Python's built-in modules — it ships with Python itself, no install needed (similar to Node's built-in fs or path).

"Private" by convention, not enforcement

A name starting with an underscore (_helper) is a signal that it's internal and not meant to be imported elsewhere — but like the MAX_USERS constant convention from Phase 1, Python doesn't actually stop you from importing it. It's a convention other developers rely on, not a hard rule.

On this page