I have an __init__
file in a folder foo/
which import some modules
from a import ClassA
from b import *
__all__ = [s for s in dir() if not s.startswith('_')]
My folder foo/
contains additional .py
files
foo/
a.py # Contain ClassA
b.py # Contain ClassB
c.py
a
import c
, so when I import a
, it automatically import c
and add it to the locals()
scope of the __init__
, even if c
isn't imported in __init__
.
I would like the __all__
of my init file to only contains the imports that I explicitly declared in the files (so just ClassA
and ClassB
). However, c
, even if not imported in the __init__
is automatically added.
How can I dynamically compute __all__
to only contains the imports that I explicitly define in my __init__.py
. Both locals()
or dir()
also return other files from the module foo
.
Ideally, the solution should be both Py2.7 Py3 compatible.