I'm trying to import a few classes from a module in another level. I can type all the classes, but I' trying to do it dynamically
if I do:
from ..previous_level.module import *
raise: SyntaxError: import * only allowed at module level
the same from myapp folder:
from myapp.previous_level.module import *
raise: SyntaxError: import * only allowed at module level
So I thought:
my_classes = ['Class_Foo', 'Class_Bar']
for i in my_classes:
from ..previous_level.module import i
raise: ImportError: cannot import name 'i'
and also:
my_classes = ['Class_Foo', 'Class_Bar']
for i in my_classes:
__import__('myapp').previous_level.module.y
raise: AttributeError: module 'myapp.previous_level.module' has no attribute 'y'
I've tried string format
, getattr()
, __getattr__
but no success.
It's impossible to do import this way, or I'm doing something wrong?