D
dubux
I am trying to import modules dynamicly from a directory (modules/) in
which i have __init__.py with the __all__ variable set. Everything
imports correctly and I have verified this however I am stuck on
actually using my classes in the dynamicly imported modules.
this bit is in my main.py (or base script) to import the modules in
the modules/ directory:
loaded_modules = []
for item in modules:
if item == '__init__.py': pass
else:
if item.endswith('.py'):
__import__('modules.' + item[0:len(item) - 3])
loaded_modules.append(item[0:len(item) - 3])
else: pass
After loading all the modules, i try to do something like:
instance = modules.modulename.class()
And I get an AttributeError. What am I doing wrong here? Help please!!
which i have __init__.py with the __all__ variable set. Everything
imports correctly and I have verified this however I am stuck on
actually using my classes in the dynamicly imported modules.
this bit is in my main.py (or base script) to import the modules in
the modules/ directory:
loaded_modules = []
for item in modules:
if item == '__init__.py': pass
else:
if item.endswith('.py'):
__import__('modules.' + item[0:len(item) - 3])
loaded_modules.append(item[0:len(item) - 3])
else: pass
After loading all the modules, i try to do something like:
instance = modules.modulename.class()
And I get an AttributeError. What am I doing wrong here? Help please!!