A growing Python application needs more than descriptive filenames: related modules also need a clear place in the directory hierarchy. Add an __init__.py file to a directory to make it a package, so its modules can be imported through a meaningful namespace. section 2.3.2
Give a utility a clear home
Suppose a string-handling add() function lives in utility.py. Move it to utilities/strings.py, add an empty utilities/__init__.py, and import it with from utilities import strings. Calling strings.add(12, 12) makes the function’s purpose clearer than an unqualified add(). section 2.3.2
from utilities import strings
def add(a, b):
return a + b
print(add(12, 12))
print(strings.add(12, 12))
The import and call show how the package and module names make the string-handling function distinct from a local add() function. section 2.3.2
The file can stay empty, but it need not. Python executes code in __init__.py when importing through the package. That makes it a possible home for package-level code, not just a marker in the file tree. section 2.3.2 section 7.3.1
The same pattern helps organize a Flask application. An app directory with __init__.py becomes a package; its initializer can provide a create_app() factory, which a separate entry-point module imports to create the Flask app instance. Packages can also be nested when the application needs a deeper hierarchy. section 7.3.1
├── app │ ├── __init__.py │ ├── static │ │ ├── css │ │ │ └── base.css │ │ ├── images │ │ │ ├── myblog_banner.png │ │ │ └── myblog_banner_50.png │ │ └── js │ │ └── index.js │ └── templates │ ├── base.html │ └── index.html └── myblog.py
The directory tree places __init__.py at the package root alongside the application’s static assets and templates. section 7.3.1



