Noel Yap
Noel Yap

Reputation: 19798

Why is __init__.py not being called?

I'm using Python 2.7 and have the following files:

./__init__.py
./aoeu.py

__init__.py has the following contents:

aoeu aoeuaoeu aoeuaoeuaoeu

so I would expect running aoeu.py to error when Python tries to load __init__.py, but it doesn't. The behavior is the same whether PYTHONPATH is set to '.' or unset.

What's going on?

Upvotes: 10

Views: 8989

Answers (1)

Wooble
Wooble

Reputation: 90037

__init__.py makes the enclosing directory a package. It won't be executed unless you actually try to import the package directly.

Upvotes: 21

Related Questions