Interview Prep/Python for DevOps/Language essentials & functions

How do modules, packages and `__init__.py` work?

BeginnerConceptLanguage essentials & functions
Answer

A module is a .py file. A package is a directory of modules, traditionally marked with __init__.py (which runs on import and can re-export names). Without __init__.py you get a namespace package, which works but can confuse tools.

import cloudaudit.checks searches sys.path: the script's directory (or current directory), PYTHONPATH, then site-packages. Prefer absolute imports inside an installed package and use the src/ layout so tests import the installed package, not a stray local folder.

All Python for DevOps questions Roadmap: Python for automation

More on Language essentials & functions