How to have "import X" importing all modules of package, but "from X import Y1" only importing/evaluating the module Y1?

Viewed 21

I have the following package/module structure:

X
|-> __init__.py
|-> y1.py
|-> y2.py

The functionality I want in my project is that when I do import X I get all the modules under the package X namespace: so, I can call X.y1.functionA() or X.y2.functionB().

That is easy enough if I write __init__.py as:

import X.y1
import X.y2

Problem is, like this, if I do an from X import y1 it still imports y2 as well. But in this case I don't want to import (or even evaluated as someone pointed in the comments) y2, I really only want y1 to get imported and evaluated.

How do I go about this?

0 Answers
Related