What's the difference between a module and a package in Python?
Module: A single Python file (.py) containing code that can be imported directly.
Package: A directory containing multiple modules with an __init__.py file.
# Module example
import utils
from utils import some_function
# Package example
import data_processing.cleaners
from data_processing import validators
What is the purpose of __init__.py in a Python package?
The __init__.py file serves multiple purposes:
- Marks the directory as a Python package
- Contains initialization code that runs when the package is imported
- Controls what gets imported with from package import *