Skip to content

Latest commit

 

History

History
30 lines (21 loc) · 900 Bytes

File metadata and controls

30 lines (21 loc) · 900 Bytes

Module 064: Packages and __init__.py

  • Phase: 7. Modules, Stdlib & Testing
  • Duration: 1.5 hours

Learning Objectives

  • Understand packages as directories of modules
  • Use __init__.py to control package initialization
  • Navigate subpackages with absolute and relative imports
  • Control exports with __all__
  • Understand namespace packages (PEP 420)

Topics Covered

  • Packages as directories with __init__.py
  • Purpose of __init__.py (can be empty or contain initialization code)
  • Subpackages and nested package structures
  • Absolute imports (from package import module)
  • Relative imports (from . import, from .. import)
  • __all__ attribute to control from package import *
  • Namespace packages (PEP 420) — implicit packages without __init__.py

Prerequisites

Module 063: Modules and Imports

Next Module

Module 065: Virtual Environments and pip