Skip to content
UPEEC

Modules and Packages

Split code into files (modules) and folders (packages), and import what you need.

Beginner
Comments 0
import math
from statistics import mean
import numpy as np

Any .py file is a module; a folder of modules is a package. The code under if __name__ == "__main__": runs only when the file is executed directly, not when imported.

Sub-topics (1)

pip and Virtual Environments

Install third-party packages with pip and isolate each project's dependencies with venv.

Beginner♥ 0🔖 0💬 0

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.