When a project has many modules, a flat folder of files becomes messy. A package groups related modules into a folder, so that names such as area.circle show the structure of the project.
What a package is
Module
Package
What it is
One .py file
A folder of modules and sub-packages
Name comes from
The file name
The folder name
Special file
None
__init__.py (marks a regular package)
Import example
import circle
import area.circle
init.py and all
__init__.py runs automatically the first time the package (or anything inside it) is imported. It can be empty, or it can set up variables, import commonly used names, and define __all__.
__all__ is a list of names; from package import * imports exactly those names (for example the sub-modules listed). Without __all__, from package import * brings in only the names defined in __init__.py itself, not the sub-modules.
A package can contain sub-packages (folders inside it), imported with longer dotted names such as shapes.solid.cube. Inside a package, modules can import their siblings with relative imports: from . import square (same package) or from .. import utils (parent package).
Key takeaways
A package is a folder of modules; __init__.py marks a regular package.
Import with import pkg.mod, from pkg import mod, or from pkg.mod import name.
__all__ in __init__.py controls from pkg import *.
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Explain the difference between a module and a package, and show the import statement needed to call area() from area/circle.py as circle.area(5).
Show worked answer
A module is a single .py file containing definitions; a package is a folder that groups related modules (and sub-packages), normally with an __init__.py file, and its modules are reached with dotted names. To call the function as circle.area(5), write from area import circle, which binds the name circle to the module area/circle.py.
MCA Online notes are made for reading on screen. Open https://mcastudy.online/mcs-201/modules-and-packages/creating-and-importing-packages/ to read this page.