Skip to content

Building 70 Projects ranging from beginner to advanced so anyone can β€” learn from, build upon, use as a reference, or even copy directly. Owned by my cybersecurity company πŸ‘‡

2.7 KB
Raw Blame
"""
Β©AngelaMos | 2026
__init__.py

Why this file exists even though it is empty

────────────────────────────────────────────────────────────────────
The one-sentence version
────────────────────────────────────────────────────────────────────
The mere PRESENCE of a file named `__init__.py` in a folder tells
Python "this folder is a package β€” you may import from it". The
file does not need to contain anything

────────────────────────────────────────────────────────────────────
Why THIS one is empty (and the src one is not)
────────────────────────────────────────────────────────────────────
Two folders in this project both have `__init__.py`, but they use
it for different jobs

  src/password_manager/__init__.py
      Has CODE inside. It re-exports the most useful classes so
      callers can write `from password_manager import UnlockedVault`
      instead of digging into submodules. This is the package's
      front door

  tests/__init__.py   <-- you are here, and it is EMPTY
      Has no code. It exists only as a MARKER so Python and pytest
      treat `tests/` as a package. That matters because some test
      files do this

          from tests.conftest import TEST_KDF_PARAMETERS

      For `tests.conftest` to be a valid dotted import path,
      `tests` has to be a package, which means this file has to
      exist. The header docstring is the only content; everything
      else is silence

────────────────────────────────────────────────────────────────────
Takeaway
────────────────────────────────────────────────────────────────────
`__init__.py` is dual-purpose

  EXISTENCE  β†’ "this folder is a package"   (always, even when empty)
  CONTENTS   β†’ optional code that runs on first import (re-exports,
               version constants, etc.)

A folder full of `.py` files with no `__init__.py` is just files;
add the `__init__.py` and it becomes something you can import as a
single unit
"""