Directory structure:
/dir1
foo.py
bar.py
/dir2
test.py
Now, I want to import all the modules present in dir1
and use it in test.py
present in dir2
. I have used an __init__.py
in /dir1
with the following contents:
from os.path import dirname, basename, isfile
import glob
modules = glob.glob(dirname(__file__)+"/*.py")
__all__ = [ basename(f)[:-3] for f in modules if isfile(f) if not f.endswith('__init__.py')]
However, when I do a from dir1 import *
in test.py
, it says no module named dir1
.
I did come across quite a few similar questions like this, but nothing seemed to solve the problem. Where am I going wrong?