__init__.py
noun
say it: “DUN-der IN-it dot PY” /ˈdʌndər ˈɪnɪt dɑt ˈpaɪ/
A file inside a folder that marks the folder as a Python package; it can be empty, or hold code that runs when the package is first imported.
What is an __init__.py file?
An __init__.py file marks a folder as a Python package. It can be empty, or hold code that runs when the package is first imported.
# shop/__init__.py
from .cart import add_item # lets people write: from shop import add_item
In a sentence
- “Adding an empty __init__.py made the shop folder a package.”
- “The __init__.py file imports add_item so callers can write from shop import add_item.”
Level: Journeyman · More Python terms at this level
Updated