Modules 101: how to avoid spaghetti, big balls of mud and houses of straw!
summary
Covers concrete module and package mechanics: how import executes and searches sys.path, why modules run once at import and how naming collisions with the standard library break code, and why from module import is dangerous with copied names and surprising globals. Shows practical bits: using __name__ == "__main__" for tests, __init__.py vs namespace packages, using __all__, shipping packages as zip, and differences in reload between Python 2 and 3*. Good for beginners who want actionable rules rather than theory.
AI-written summary · about
chapters (19)
- 0:00Intro
- 1:05"Building" software
- 4:14Getting design right is critical
- 6:11Some basic design principles
- 7:50Why use modules and packages?
- 8:14Far nicer than spaghetti!
- 8:34What is a module?
- 10:11Module search paths
- 10:58Namespaces
- 15:14Avoid clutter and clashes
- 15:44reload
- 18:02Executing modules
- 19:12Documenting modules
- 21:10Defining packages: __init__.py
- 22:01Subpackages
- 22:34Fun & interesting modules
- 23:04Executable modules
- 23:21Advanced topics to explore next
- 25:19These notes
related talks
21mUnderstanding the Magic of Python Modules and Packages
45mWhat happens when you import a module?
28mImport Deep Dive
30mImporting Without "import": Behind the Scenes of importlib
26mWhat happens behind execution of an `import` statement?
29m"from where?!? import what?!?"
23mEverything is a Python module
21mHacking the Python Import System
